2010-09-13 76 views
0

以下所有内容在rails console(Rails 3)中都能很好地工作,除了0 ... 0的人类可读形式不是0会导致错误的Rails'number_to_human(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 123456789
=> "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>' 

回答