请听我说,这是我遇到的一个奇怪的错误。让我们说discountValue = 5
和grandTotal = 10
,discountShow
将正确输出并格式化结果。但如果grandTotal
为greater
而不是999
,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 + " €");
}
答案 0 :(得分:0)
你可以试试这个。
将format('0,0.00');
更改为format('0,0.[00]');
<强> JsFiddle Demo 强>
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();
&#13;
<script src="//cdnjs.cloudflare.com/ajax/libs/numeral.js/1.4.5/numeral.min.js"></script>
&#13;