四舍五入到最接近的十分之一? [英] Round up to the nearest tenth?
本文介绍了四舍五入到最接近的十分之一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要四舍五入到最接近的十分之一.我需要的是ceil
,但精确到小数点后一位.
I need to round up to the nearest tenth. What I need is ceil
but with precision to the first decimal place.
示例:
10.38 would be 10.4
10.31 would be 10.4
10.4 would be 10.4
因此,如果金额超过整数十分之一,则应四舍五入.
So if it is any amount past a full tenth, it should be rounded up.
我正在运行Ruby 1.8.7.
I'm running Ruby 1.8.7.
推荐答案
这通常适用:
ceil(number*10)/10
所以在Ruby中应该像这样:
So in Ruby it should be like:
(number*10).ceil/10.0
这篇关于四舍五入到最接近的十分之一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文