INT Function

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?
 
A

Allen Browne

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.
 
J

Jamie Collins

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.

--
 

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

Top