I have a field ThisAmount defined as Double
Using the following code:
ThisAmount=4747.69
ThisAmount=ThisAmount * 100
ThisAmount=INT(ThisAmount)
ThisAmount=ThisAmount/100
The INT function converts the value of 474769 to 474768
This is part of a financial program allocationg invoice amounts by percentage.
Because a percenatage of an amount can have many decimal places I am trying to ensure that the value is set to only 2 decimal places.
Instead of assigning the result of this operation to your Double variable, try assigning it to a long, or a currency. Like this:
[tt]
Dim ThisAmount as Double
Dim lAmount as Long
ThisAmount=4747.69
lAmount=ThisAmount * 100.0
ThisAmount=lAmount/100.0
[/tt]
I think this will do the truncation properly (and not round up). If this doesn't work, try:
[tt]
ThisAmount=4747.69
ThisAmount=ThisAmount * 100.0
ThisAmount=Int(ThisAmount + 0.5) - 1.0
ThisAmount=ThisAmount/100.0
[/tt]
You should be aware that the division by 100 is also likely to introduce rounding errors, and may negate all your efforts.
I think Sparrow might be hitting a problem with base-2 rounding. 4747.69 seems to be one of those numbers which doesn't have a precise representation in IEEE floating point format.
When the Int() is called, it makes a rounding decision based on the binary image of the number, and thus rounds down. By assigning it to a Long (or currency) as an intermediate step, you get it out of IEEE format and into a format where 474769 can be represented precisely.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.