Getting integer from decimal

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Peterson

    #1

    Getting integer from decimal

    Hello

    I have a method that returns a decimal. I need to get the lowest integer
    value from this decimal. For example from "4.9764" I need to get "4", or
    from "13.134" I need "13". Is there a .Net method I can use to do this? If
    not, maybe someone throw me a tidbit of code to so this..

    TIA
    Steve


  • Robin Tucker

    #2
    Re: Getting integer from decimal

    theInteger = CInt(theValue)

    "Steve Peterson" <speterson@nosp am.com> wrote in message
    news:eywceVxgFH A.3000@tk2msftn gp13.phx.gbl...[color=blue]
    > Hello
    >
    > I have a method that returns a decimal. I need to get the lowest integer
    > value from this decimal. For example from "4.9764" I need to get "4", or
    > from "13.134" I need "13". Is there a .Net method I can use to do this? If
    > not, maybe someone throw me a tidbit of code to so this..
    >
    > TIA
    > Steve
    >[/color]


    Comment

    • Kerry Moorman

      #3
      RE: Getting integer from decimal

      Steve,

      Depending on how you need to handle negative numbers, you might use the INT
      function or the FIX function.

      Kerry Moorman


      "Steve Peterson" wrote:
      [color=blue]
      > Hello
      >
      > I have a method that returns a decimal. I need to get the lowest integer
      > value from this decimal. For example from "4.9764" I need to get "4", or
      > from "13.134" I need "13". Is there a .Net method I can use to do this? If
      > not, maybe someone throw me a tidbit of code to so this..
      >
      > TIA
      > Steve
      >
      >
      >[/color]

      Comment

      • Steve Peterson

        #4
        Re: Getting integer from decimal

        Thx guys!
        Steve

        "Steve Peterson" <speterson@nosp am.com> wrote in message
        news:eywceVxgFH A.3000@tk2msftn gp13.phx.gbl...[color=blue]
        > Hello
        >
        > I have a method that returns a decimal. I need to get the lowest integer
        > value from this decimal. For example from "4.9764" I need to get "4", or
        > from "13.134" I need "13". Is there a .Net method I can use to do this? If
        > not, maybe someone throw me a tidbit of code to so this..
        >
        > TIA
        > Steve
        >[/color]


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Getting integer from decimal

          "Steve Peterson" <speterson@nosp am.com> schrieb:[color=blue]
          > I have a method that returns a decimal. I need to get the lowest integer
          > value from this decimal. For example from "4.9764" I need to get "4", or
          > from "13.134" I need "13". Is there a .Net method I can use to do this? If
          > not, maybe someone throw me a tidbit of code to so this..[/color]

          Take a look at 'Int', 'Fix', and 'Math.Floor'.

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://classicvb.org/petition/>

          Comment

          • Inge Henriksen

            #6
            Re: Getting integer from decimal

            Hi, this is from the MSDN library that might help to clarify things:

            When the fractional part is exactly 0.5, CInt and CLng always round it to
            the nearest even number. For example, 0.5 rounds to 0 and 1.5 rounds to 2.
            CInt and CLng differ from the Fix and Int functions, which truncate, rather
            than round, the fractional part of a number. Also, Fix and Int always return
            a value of the same type as is passed in.


            "Steve Peterson" <speterson@nosp am.com> skrev i melding
            news:eywceVxgFH A.3000@tk2msftn gp13.phx.gbl...[color=blue]
            > Hello
            >
            > I have a method that returns a decimal. I need to get the lowest integer
            > value from this decimal. For example from "4.9764" I need to get "4", or
            > from "13.134" I need "13". Is there a .Net method I can use to do this? If
            > not, maybe someone throw me a tidbit of code to so this..
            >
            > TIA
            > Steve
            >[/color]



            Comment

            Working...