javascript parseFloat bug

413 views Asked by At

I am subtracting multiple textboxes using JavaScript. I'm adding the total amount in the textboxes.When amount is first entered it works fine but when I change the amount and save it again there is a bug.The value is pulled from database the second time and is in "00.00" format.

The problem is when the value is a 4 digit value say "6500.00" it changes to "6.00". It shows as 6500.00 in the webpage but during calculation in JavaScript it calculates as "6.00".it works fine for 3 digit value like "400.50".Can somebody tell me what's the problem here.

JavaScript:

function fill_balance() 
{
var total = document.getElementById("total").value;
var payment = document.getElementById("payment").value; 
document.getElementById("balance").value = parseFloat(total) - parseFloat(payment);
}

P.S: I use number_format() function to change the format to 00.00

0

There are 0 answers