开发者

Would Rails' number_to_human(0) giving an error be a bug?

All of the following works well in rails console (Rails 3) except for 0... wouldn't the human readable form of 0 just be 0?

irb(main):015:0> helper.number_to_human 1
=> "1"
irb(main):016:0> helper.number_to_human 2
=> "2"
irb(main):017:0> helper.number_to_human 200
=> "200"
irb(main):018:0> helper.number_to_human 3000
=> "3 Thousand"
irb(main):019:0> helper.number_to_human 30000
=> "30 Th开发者_运维技巧ousand"
irb(main):020:0> helper.number_to_human 300000
=> "300 Thousand"
irb(main):007:0> helper.number_to_human 1234567
=> "1.23 Million"
irb(main):008:0> helper.number_to_human 12345678
=> "12.3 Million"
irb(main):009:0> helper.number_to_human 123456789
=> "123 Million"
irb(main):010:0> helper.number_to_human 1234567890
=> "1.23 Billion"
irb(main):011:0> helper.number_to_human 12345678901
=> "12.3 Billion"
irb(main):012:0> helper.number_to_human 123456789012
=> "123 Billion"
irb(main):013:0> helper.number_to_human 1234567890123
=> "1.23 Trillion"
irb(main):014:0> helper.number_to_human 0
FloatDomainError: -Infinity
        from c:/ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_view/helpers/number_helper.rb:462:in `floor'
        from c:/ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.0/lib/action_view/helpers/number_helper.rb:462:in `number_to_human'
        from (irb):14
        from c:/ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands/console.rb:44:in `start'
        from c:/ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands/console.rb:8:in `start'
        from c:/ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:23:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'


It's a bug report already

https://rails.lighthouseapp.com/projects/8994/tickets/5532-number_to_human0-causes-exception

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜