02-17-2008, 03:31 AM
Dear VB people,
Thinking to something very easy:
We have a value 4.9999 and we want to remove the decimals
dim N as long
N = 4.9999
msgbox int(N) 'gives 5 instead of 4
With which function we get the value 4?
Functions Abs / Format gives the same result!
02-17-2008, 04:20 AM
There is the int() function which simply removes everything after the dot but since you want it to be rounded to the nearest whole number you should use Round()
Function Round(Number, [NumDigitsAfterDecimal As Long])
For a whole number dont specify NumDigitsAfterDecimal (it will default to 0)
Edit: Seems i read it wrong. You want it rounded down instead. The int() function does do that. Not sure why its not working for you
02-17-2008, 04:25 AM
Ahh. I see whats wrong now. Because you are using a long number it gets rounded before you even get to int(). If you change your message box to just display the value in N without int() around it you will notice its already been rounded to 5.
There is a simple workaround for this. Declare N as a double instead of long
02-17-2008, 01:38 PM
Thanks a lot,