[LRUG] Prices and Precision
Marcus Roberts
marcus at marcusr.org.uk
Sun Nov 18 03:32:41 PST 2007
I'm sure this is down to precision in the Float library, but under irb
in Ruby 1.8.6
>> (3.0 * 0.175)
=> 0.525
>> (0.525 * 100).round
=> 53
>> ((3.0 * 0.175)*100).round
=> 52
I'm trying to calculate my VAT on an price, but get different results
on different machines and in different places.
Everything seems to be a Float throughout.
What's the best way to store prices in a Ruby (Rails) app? What's the
best SQL type for mySQL?
Thanks
Marcus
More information about the Chat
mailing list