【问题标题】:Would Rails' number_to_human(0) giving an error be a bug?Rails 的 number_to_human(0) 给出错误会是一个错误吗?
【发布时间】:2010-09-13 04:32:06
【问题描述】:

除了 0 之外,以下所有内容在 rails console (Rails 3) 中都能正常工作...0 的人类可读形式不就是 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 Thousand"
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>'

【问题讨论】:

    标签: ruby-on-rails actionview


    【解决方案1】:
    猜你喜欢
    • 2016-09-05
    • 1970-01-01
    • 2019-01-04
    • 1970-01-01
    • 2015-02-12
    • 2011-12-08
    • 1970-01-01
    • 1970-01-01
    • 2014-11-10
    相关资源
    最近更新 更多