如何在JavaScript或decimal.js中编写Excel CEILING(数字,重要性)函数
CEILING(10,3)= 12 向上舍入到最接近的3
CEILING(36,7)= 42 四舍五入到最接近的7
CEILING(560,100)= 600 向上舍入到最接近的100
CEILING(6.36,0.05)= 6.40 四舍五入到最接近的0.05
答案 0 :(得分:3)
这是一个解决方案:
function ceiling(number, significance) {
return Math.ceil(number / significance) * significance;
}
$(document).ready(function() {
console.log(ceiling(10, 3));
console.log(ceiling(36, 7));
console.log(ceiling(560, 100));
console.log(ceiling(6.36, 0.05));
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;