가격을 수정하고 싶은데요.
본문
외국에 들어가는 쇼핑몰이라
화폐단위가 조금 틀려서요.
1000.123 이런식으로 들어가야하는데
토탈 금액에서 수정이 되질 않네요.
function price_calculate()
{
var it_price = parseInt($("input#it_price").val());
if(isNaN(it_price))
return;
var $el_prc = $("input.io_price");
var $el_qty = $("input[name^=ct_qty]");
var $el_type = $("input[name^=io_type]");
var price, type, qty, total = 0;
$el_prc.each(function(index) {
price = parseInt($(this).val());
qty = parseInt($el_qty.eq(index).val());
type = $el_type.eq(index).val();
if(type == "0") { // 선택옵션
total += (it_price + price) * qty;
} else { // 추가옵션
total += price * qty;
}
});
$("#sit_tot_price").empty().html("<span style='font-size:18px'>구매예정금액</span> <span style='font-size:24px'><font color='#e60012'><b>"+String(total)+"</font></b></span> KD");
}
이부분을 어떻게 수정해야 소수점 그대로 계산되어 나올까요?
답변 1
parseInt 는 소수점 아래는 보여주지 않습니다
1000.123 와 같은 경우
parseInt(1000.123 * 1000)/1000 으로 표현을 해야 수숫점 아래 까지 표현이 됩니다