diff options
author | Bernardo de Pádua <berpasan@gmail.com> | 2010-04-01 01:19:09 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-04-01 07:25:14 +0200 |
commit | 81e69332466003732846bd7dbc04e8550bfe16a1 (patch) | |
tree | 61ae8b484c83068a29a0481c6533d22e7a1c452c /actionpack/lib/action_view/helpers | |
parent | 3859828d89d378986af0fc2390608b00aad5e912 (diff) | |
download | rails-81e69332466003732846bd7dbc04e8550bfe16a1.tar.gz rails-81e69332466003732846bd7dbc04e8550bfe16a1.tar.bz2 rails-81e69332466003732846bd7dbc04e8550bfe16a1.zip |
Fix error in number_with_precision with :significant option and zero value [#4306 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r-- | actionpack/lib/action_view/helpers/number_helper.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 605e5d5873..01fecc0f23 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -273,8 +273,12 @@ module ActionView strip_insignificant_zeros = options.delete :strip_insignificant_zeros if significant and precision > 0 - digits = (Math.log10(number) + 1).floor - rounded_number = BigDecimal.new((number / 10 ** (digits - precision)).to_s).round.to_f * 10 ** (digits - precision) + if number == 0 + digits, rounded_number = 1, 0 + else + digits = (Math.log10(number) + 1).floor + rounded_number = BigDecimal.new((number / 10 ** (digits - precision)).to_s).round.to_f * 10 ** (digits - precision) + end precision = precision - digits precision = precision > 0 ? precision : 0 #don't let it be negative else |