Actions
Bug #9540
closedNumber formatting with 4.225 fails
Bug #9540:
Number formatting with 4.225 fails
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
Description
Hi,
When I’m trying to floor number with line “"%.2f" % 4.225”, I get 4.22 as result, instead of 4.23. Rounding for example with 0.025 correctly results to 0.03.
I tested this with both newest 2.0.0 patchset build and 2.1.0.
Some example output done with irb:
Updated by shugo (Shugo Maeda) over 12 years ago
- Status changed from Open to Rejected
Samu Voutilainen wrote:
When I’m trying to floor number with line “"%.2f" % 4.225”, I get 4.22 as result, instead of 4.23. Rounding for example with 0.025 correctly results to 0.03.
It's because 4.225 doesn't have an exact representation in binary floating point.
Please use BigDecimal instead of Float if you need an exact decimal value.
Actions