Getting integer from decimal

  • Thread starter Thread starter Steve Peterson
  • Start date Start date
S

Steve Peterson

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
 
Steve,

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

Kerry Moorman
 
Steve Peterson said:
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..

Take a look at 'Int', 'Fix', and 'Math.Floor'.
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top