diff options
author | Kenta Murata & Akira Matsuda <mrkn@cookpad.com> | 2013-12-20 15:35:13 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2013-12-20 16:26:35 +0900 |
commit | 9e997e9039435617b6a844158f5437e97f6bc107 (patch) | |
tree | 2d1e8853e3ac9b5e45fc5e06ad3ce667e6675401 /activesupport/test | |
parent | c437a98acaf759d53a85151947709f5efe499a27 (diff) | |
download | rails-9e997e9039435617b6a844158f5437e97f6bc107.tar.gz rails-9e997e9039435617b6a844158f5437e97f6bc107.tar.bz2 rails-9e997e9039435617b6a844158f5437e97f6bc107.zip |
Fix AS::NumberHelper results with large precisions
before:
ActiveSupport::NumberHelper.number_to_rounded '3.14159', precision: 50
=> "3.14158999999999988261834005243144929409027099609375"
after:
ActiveSupport::NumberHelper.number_to_rounded '3.14159', precision: 50
=> "3.14159000000000000000000000000000000000000000000000"
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/number_helper_test.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/test/number_helper_test.rb b/activesupport/test/number_helper_test.rb index 111db59b2b..6d8d835de7 100644 --- a/activesupport/test/number_helper_test.rb +++ b/activesupport/test/number_helper_test.rb @@ -123,6 +123,12 @@ module ActiveSupport assert_equal("10.00", number_helper.number_to_rounded(9.995, :precision => 2)) assert_equal("11.00", number_helper.number_to_rounded(10.995, :precision => 2)) assert_equal("0.00", number_helper.number_to_rounded(-0.001, :precision => 2)) + + assert_equal("111.23460000000000000000", number_helper.number_to_rounded(111.2346, :precision => 20)) + assert_equal("111.23460000000000000000", number_helper.number_to_rounded(Rational(1112346, 10000), :precision => 20)) + assert_equal("111.23460000000000000000", number_helper.number_to_rounded('111.2346', :precision => 20)) + assert_equal("111.23460000000000000000", number_helper.number_to_rounded(BigDecimal(111.2346, Float::DIG), :precision => 20)) + assert_equal("111.2346" + "0"*96, number_helper.number_to_rounded('111.2346', :precision => 100)) end end @@ -155,6 +161,14 @@ module ActiveSupport assert_equal "10.0", number_helper.number_to_rounded(9.995, :precision => 3, :significant => true) assert_equal "9.99", number_helper.number_to_rounded(9.994, :precision => 3, :significant => true) assert_equal "11.0", number_helper.number_to_rounded(10.995, :precision => 3, :significant => true) + + assert_equal "9775.0000000000000000", number_helper.number_to_rounded(9775, :precision => 20, :significant => true ) + assert_equal "9775.0000000000000000", number_helper.number_to_rounded(9775.0, :precision => 20, :significant => true ) + assert_equal "9775.0000000000000000", number_helper.number_to_rounded(Rational(9775, 1), :precision => 20, :significant => true ) + assert_equal "97.750000000000000000", number_helper.number_to_rounded(Rational(9775, 100), :precision => 20, :significant => true ) + assert_equal "9775.0000000000000000", number_helper.number_to_rounded(BigDecimal(9775), :precision => 20, :significant => true ) + assert_equal "9775.0000000000000000", number_helper.number_to_rounded("9775", :precision => 20, :significant => true ) + assert_equal "9775." + "0"*96, number_helper.number_to_rounded("9775", :precision => 100, :significant => true ) end end |