将值四舍五入为2个小数 [英] round value to 2 decimals javascript
本文介绍了将值四舍五入为2个小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最终值有一个小问题,我需要四舍五入到小数点后两位.
I have a small issue with the final value, i need to round to 2 decimals.
var pri='#price'+$(this).attr('id').substr(len-2);
$.get("sale/price?output=json", { code: v },
function(data){
$(pri).val(Math.round((data / 1.19),2));
});
});
感谢您的帮助.
解决方案:$(pri).val(Math.round((data / 1.19 * 100 )) / 100);
推荐答案
只需将数字乘以100,四舍五入,然后将结果数字除以100.
Just multiply the number by 100, round, and divide the resulting number by 100.
这篇关于将值四舍五入为2个小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文