Question

Do not quite understand the jquery but in spite of that I have created the following code, but the field IGV dollar does not throw me two decimal places.

For example if I enter 1200 gives me a value of 216 when it should be 216.00

Example: 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)
}
Was it helpful?

Solution

Here is the solution,

$('.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)
}

I have even made the change to your JSFiddle Code you can check that out. http://jsfiddle.net/XyqCw/1/

OTHER TIPS

Because you are not using toFixed(2) on that number like you are doing in other places.

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

to

$('#igvdolares').val(igvdolares.toFixed(2));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top