Home Ruby 有效的对小数进行四舍五入'%.2f'%0.12323=0.12
Post
Cancel

Ruby 有效的对小数进行四舍五入'%.2f'%0.12323=0.12

如题.

有时候使用  round(2) 会出现  0.00000000000000001  这样的情况.

使用 '%.2f' % a 就不会出现.

This post is licensed under CC BY 4.0 by the author.