jQuery-数字格式问题 [英] jquery - number formatting issue
本文介绍了jQuery-数字格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.field.js" type="text/javascript"></script>
<script src="js/jquery.calculation.js" type="text/javascript"></script>
<script>
$(function() {
$('input[name^=sum]').keyup(function() {
var sum1 = parseFloat($('input[name=sum1]').val()) || 0;
var sum2 = parseFloat($('input[name=sum2]').val()) || 0;
var sum3 = parseFloat($('input[name=sum3]').val()) || 0;
$('#c_card_amount').val(sum1*sum3/100);
$('#total_inc_charges').val((sum1*sum3/100)+sum1);
});
});
</script>
在输入字段中,我想以1,000.00格式显示数字.
In the input fields I would like to show the numbers in 1,000.00 format.
如何格式化这样的数字?现在,在计算之后,数字有时会像452.25600000001那样混乱.我也想避免这种情况.最好正确地控制数字.
How can I format the numbers like this? Right now after the calculation numbers sometimes gets messed up like 452.25600000001. I would like to avoid that as well. Would be nice to rule the numbers properly.
感谢您的帮助.
推荐答案
我建议您尝试 jQuery格式在此问题中提到:在javascript中格式化数字.
I would recommend you to try jQuery Format as mentioned in this question: Format numbers in javascript.
以下是jQuery格式的示例:
Below is an example of jQuery Format:
$.format.locale({
number: {
groupingSeparator: ',',
decimalSeparator: '.'
}
});
$.format.number(1000, '#,###.00'); // result: 1,000.00
$.format.number(452.25600000001, '#,###.00'); // result: 452.26
这篇关于jQuery-数字格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文