i'm trying to set an output value from 2 fields to 2 decimals.
i've tried doing this with: .toFixed(2)
but it didn't work for me. I tried doing this:
calculate = function () {
var total = document.getElementById('totaal').value;
var btw = document.getElementById('percentage').value;
document.getElementById('btw').value = parseInt(total.toFixed(2)) * parseInt(btw.toFixed(2)) / 100;
}
If the field ends on a number with 2 decimals (for example: 3,45) it is working correctly.
But if it ends with a 0, it does not show the 0.
I think this shoudn't be this mutch of a deal but i'm just trying for half a day now...
Thanks in advance!
When you use
parseInt()
you then get the numbers after the decimal points removed, try doing this :parseFloat
converts the string (and it's necessary because input values are string) in the input to a float, then divide by 100 and call.toFixed(2)
on the result.