请听我说,这是我遇到的一个奇怪的错误。假设discountValue = 5
和grandTotal = 10
,discountShow
将正确输出和格式化结果。但是如果grandTotal
比999
greater
,discountShow
将输出一个NaN
function discount_compute() {
var discountValue = parseFloat($('#discount').val().replace(',', '.'));
var discountTotal = grandTotal * (1 - (discountValue / 100));
var discountShow = numeral(discountTotal.toFixed(2)).format('0,0.00');
$('.net-total-discount').html(discountShow + " €");
}
你可以
试试这个。
将format('0,0.00');
更改为format('0,0.[00]');
JsFiddle 演示
function discount_compute() {
var grandTotal = 10;
var discountValue = 5;
var discountTotal = grandTotal * (1 - (discountValue / 100));
var discountShow = discountTotal.toFixed(2)
var discountShow = numeral(discountTotal.toFixed(2)).format('0,0.[00]');
document.write(discountShow + " €");
}
discount_compute();
<script src="//cdnjs.cloudflare.com/ajax/libs/numeral.js/1.4.5/numeral.min.js"></script>