在Rails中将数字格式化为小数

时间:2012-11-11 00:40:25

标签: ruby-on-rails numbers format decimal

  

可能重复:
  Ruby Regex to round trailing zeros

我的数据库表中有一个十进制列(精度:8,比例:2),我正在寻找一种简单的方法来格式化数字,如下所示:

# Currently, when I pass the data to json format, it shows like:
12    -> "12.0"
12.00 -> "12.0"
12.50 -> "12.5"
12.58 -> "12.58"

# What I need is strip any 0 at the end.
12    -> "12"
12.00 -> "12"
12.50 -> "12.5"
12.58 -> "12.58"

0 个答案:

没有答案