Ton*_*shi 3 ruby regex
我如何转换"$ 10.80"为十进制?使用正则表达式?
"$ 10.80"
tho*_*ron 6
它可能不是最好的方法,但这是有效的:
"$ 10.80".match(/[0-9|\.]+/)[0].to_f
Jan*_*Jan 6
s = "$ 10.80" BigDecimal.new s.match(/(\d+\.\d+)/)[1]
以BigDecimal的形式返回值以保持精度.
归档时间:
14 年,2 月 前
查看次数:
2517 次
最近记录: