INT Function

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I am getting some odd results when using the int() function with VBA.
Here is what is happening:

quantity = dblTransactionQuantity
quantityWithoutDecimalPlaces = dblTransactionQuantity * 1000
integerpart = Int(quantityWithoutDecimalPlaces)

When you set the dblTransactionQuantity to 1.001 intergerpart returns
1000, but it should return 1001. Is this a floating point error? If
you sent the dblTransactionQuantity as 1.002 the correct answer is
returned (1002). Any suggestions?
 
Yes. It's a floating point error.

Try Round() instead of Int().

Alternatively, use Currency instead of Double if you need no more than 4
decimal places.
 
Yes. It's a floating point error.

Try Round() instead of Int().

Alternatively, use Currency instead of Double if you need no more than 4 decimal places.

Or indeed, the DECIMAL data type, the fixed point type that Jet uses
for 'native' decimal numbers (Allen, I know you don't recommend
DECIMAL, even though you know they've fixed the sort order bug, but I
can :)

Jamie.

--
 
Back
Top