Authored by lijing

强制保留两位小数

... ... @@ -158,8 +158,9 @@ $(
// 插入倒计时
addTimeout($('.price-date'));
addTimeout($('.text-info'));
$('.current-price').text('¥' + data.secKillPrice).show();
$('.sale-price').text('¥' + data.secKillPrice).show();
let secKillPrice = toDecimal2(data.secKillPrice);
$('.current-price').text('¥' + secKillPrice).show();
$('.sale-price').text('¥' + secKillPrice).show();
$('.chose-items .num').find('.clearfix').append(
'<span class="limit-num-text">限购1件</span>'
);
... ... @@ -300,3 +301,22 @@ function addTimeout(obj) {
'</div>'
);
}
// 强制保留2位小数点
function toDecimal2(num) {
var f = parseFloat(num);
if (isNaN(f)) {
return false;
}
var f = Math.round(num * 100) / 100;
var s = f.toString();
var rs = s.indexOf('.');
if (rs < 0) {
rs = s.length;
s += '.';
}
while (s.length <= rs + 2) {
s += '0';
}
return s;
}
... ...