嘿,我将如何将一个数字四舍五入到最接近 3 的倍数?
Hay, how would i go about rounded a number up the nearest multiple of 3?
即
25 would return 27
1 would return 3
0 would return 3
6 would return 6
谢谢
if(n > 0)
return Math.ceil(n/3.0) * 3;
else if( n < 0)
return Math.floor(n/3.0) * 3;
else
return 3;
这篇关于将数字四舍五入到最接近的 3 的倍数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!