Changeset 9086
- Timestamp:
- 03/24/08 21:12:55 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/number_helper.rb (modified) (1 diff)
- trunk/actionpack/test/template/number_helper_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r9083 r9086 1 1 *SVN* 2 2 3 # Allow the #simple_format text_helper to take an html_options hash for each paragraph. #2448 [Francois Beausoleil, thechrisoshow] 3 * Fixed NumberHelper#number_with_precision to properly round in a way that works equally on Mac, Windows, Linux (closes #11409, #8275, #10090, #8027) [zhangyuanyi] 4 5 * Allow the #simple_format text_helper to take an html_options hash for each paragraph. #2448 [Francois Beausoleil, thechrisoshow] 4 6 5 7 * Fix regression from filter refactoring where re-adding a skipped filter resulted in it being called twice. [rick] trunk/actionpack/lib/action_view/helpers/number_helper.rb
r9052 r9086 145 145 # ==== Examples 146 146 # number_with_precision(111.2345) # => 111.235 147 # number_with_precision(111.2345, 2) # => 111.2 4147 # number_with_precision(111.2345, 2) # => 111.23 148 148 # number_with_precision(13, 5) # => 13.00000 149 149 # number_with_precision(389.32314, 0) # => 389 150 150 def number_with_precision(number, precision=3) 151 "%01.#{precision}f" % number151 "%01.#{precision}f" % ((Float(number) * (10 ** precision)).round.to_f / 10 ** precision) 152 152 rescue 153 153 number trunk/actionpack/test/template/number_helper_test.rb
r9052 r9086 57 57 def test_number_with_precision 58 58 assert_equal("111.235", number_with_precision(111.2346)) 59 assert_equal("31.83", number_with_precision(31.825, 2)) 59 60 assert_equal("111.23", number_with_precision(111.2346, 2)) 60 61 assert_equal("111.00", number_with_precision(111, 2)) 61 62 assert_equal("111.235", number_with_precision("111.2346")) 63 assert_equal("31.83", number_with_precision("31.825", 2)) 62 64 assert_equal("112", number_with_precision(111.50, 0)) 63 65 assert_equal("1234567892", number_with_precision(1234567891.50, 0))