新手问题 decimal 与 float

aloha · July 06, 2012 · Last by physaris replied at January 21, 2014 · 3710 hits

新建的 model,在 migrate 声明成 decimal,:scale=>1 写 99.9 存进去的值是 99.9,但是取出来 view 里面显示的就是 99.90000000000001,rails console 取出来也是 99.90000000000001 是不是 rails 会自动把 decimal 转成 float,如果要显示 1 位小数,是不是每次都要调 xxx.round()

"%.1f" % 99.90000000000001

碰到了同样地问题,楼主知道其中原因了吗,有没有解决方案。 存数据库的时候已经 round 过一次了,取出来还得再来一次,有点浪费资源。

You need to Sign in before reply, if you don't have an account, please Sign up first.