找不到两个十进制jquery圆

时间:2014-03-04 20:21:41

标签: jquery decimal

不太了解jquery但是尽管我已经创建了以下代码,但是字段IGV美元并没有给我两个小数位。

例如,如果我输入1200,则值216时应为216.00

示例: http://jsfiddle.net/XyqCw/

$('.precio').keyup(function () {
    var igvdolaresround = (Number($(this).val()) * 18) / 100;
    var igvdolares = igvdolaresround /* :( not found (igvdolaresround).toFixed(2); */
    var totaldolares = ((Number($(this).val()) + igvdolares).toFixed(2));
    var igvsoles = ((igvdolares * 2.80).toFixed(2));
    var totalsoles = ((totaldolares * 2.80).toFixed(2));
    $('#igvdolares').val(igvdolares);
    $('#totaldolares').val(totaldolares);
    $('#igvsoles').val(igvsoles);
    $('#totalsoles').val(totalsoles);
});

function maxLengthCheck(object) {
    if (object.value.length > object.maxLength) object.value = object.value.slice(0, object.maxLength)
}

2 个答案:

答案 0 :(得分:1)

因为您没有像在其他地方那样使用toFixed(2)

$('#igvdolares').val(igvdolares);

$('#igvdolares').val(igvdolares.toFixed(2));

答案 1 :(得分:1)

这是解决方案,

$('.precio').keyup(function () {
    var igvdolaresround = (Number($(this).val()) * 18) / 100;
    console.log(Number(igvdolaresround));
    var igvdolares = igvdolaresround /* not found (igvdolaresround).toFixed(2); */
    var totaldolares = ((Number($(this).val()) + igvdolares).toFixed(2));
    var igvsoles = ((igvdolares * 2.80).toFixed(2));
    var totalsoles = ((totaldolares * 2.80).toFixed(2));
    $('#igvdolares').val(Number(igvdolares).toFixed(2));
    $('#totaldolares').val(totaldolares);
    $('#igvsoles').val(igvsoles);
    $('#totalsoles').val(totalsoles);
});

function maxLengthCheck(object) {
    if (object.value.length > object.maxLength) object.value = object.value.slice(0, object.maxLength)
}

我甚至对您的JSFiddle代码进行了更改,您可以检查出来。 http://jsfiddle.net/XyqCw/1/