How do I get the word-equivalent of a floating-point number? E.g.
- 10.24 → ten point twenty-four
- 5.113 → five point hundred and thirteen
How do I get the word-equivalent of a floating-point number? E.g.
有一个名为numbers_and_words的宝石!到目前为止,我已经在几个项目中使用它,没有任何问题。
使用语言宝石:
require 'linguistics'
Linguistics.use( :en )
p 10.24.en.numwords #=> "ten point two four"
p 5.113.en.numwords #=> "five point one one three"
或尝试按照此答案中的说明使用此技巧来获得更高的精度:
require "linguistics"
Linguistics::use(:en)
class Float
def my_numwords
self.to_s.split('.').collect { |n| n.en.numwords }.join(' point ')
end
end
p 10.24.my_numwords #=> "ten point two four"
p 5.113.my_numwords #=> ""five point one hundred and thirteen"