Forum OpenACS Q&A: Re: Tcl weird behaviour with math

Collapse
Posted by Antonio Pisano on
Thanks for your fast and clear explanation Benjamin, I will update my procs so they truncate all digits beyond required precision before being ceiled and this should do the trick.

All the best

Antonio

Collapse
Posted by Gustaf Neumann on
The best is to calculate internally the only the smallest unit (i.e. cents) in integers, calculate with these, and format these as required to dollar, euro, etc.

In the more general case, you might want to look into the tcl decimal arithmetic package: http://wiki.tcl.tk/28305

In some simple cases, it might be sufficient to work with a comparison operator with an espilon fuzz value (e.g. withinEpsilon is http://wiki.tcl.tk/879)

best regards
-gustaf neumann