有人知道在rails中将数字转换为英文数字的方法吗?
我找到了一些Ruby脚本来将数字转换为英文单词以获得相应的单词.
而不是在ruby中编写脚本,我觉得可以使用直接功能.
例如.1 - >一,二 - >二.
Geo*_*roy 11
还有人性化的宝石完全符合您的要求......
require 'humanize'
23.humanize # => "twenty three"
0.42.humanize(decimals_as: :digits) # => "zero point four two"
Run Code Online (Sandbox Code Playgroud)
Mis*_*cha 10
不,你必须自己写一个函数.最接近您想要的是number_to_human,但不会转换1为One.
以下是一些可能有用的网址:
小智 5
您还可以使用to_words gem.
这个宝石将整数转换成单词.
例如
1.to_words # one ,
100.to_words # one hundred ,
101.to_words # one hundred and one
Run Code Online (Sandbox Code Playgroud)
它还转换负数.
| 归档时间: |
|
| 查看次数: |
24292 次 |
| 最近记录: |