Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Truncating a number

I have a number (a double) that I want to truncate to only 2 places after the decimal point. The number is typicly larger in decimal places (like 5 or 6). I do not want to round up or down, just truncate.

For example if my number is 12345.6789 I want to end up with 12345.67, I have tried Format(12345.6789,"#####.00") but that rounds and I get 12345.68

Any idea on how to do that?
[399 byte] By [AM003295] at [2007-11-11 11:59:24]
# 1 Re: Truncating a number
try this :

cdbl(left(Format(12345.6789,"#####.000"),len(Format(12345.6789,"#####.00")-1)))

I know it's crasy somewhat but you have a special case, I think every body need rounding ...
Amahdy at 2007-11-11 17:20:46 >
# 2 Re: Truncating a number
... or ...

NewNumber = INT(OldNumber *100) / 100
gupex at 2007-11-11 17:21:46 >