Here is a simple scenario. I want to display the subtraction of two values on my website:
//The value on my website is: "75,00" var fullcost = parseFloat($("#fullcost").text()); //The value on my website is: "0,03" var auctioncost = parseFloat($("#auctioncost").text()); alert(fullcost); //Output: 75 alert(auctioncost); //Output: 0
Can anyone tell me what I'm doing wrong?
The parseFloat function of javascript does not accept regional parameters. So you need to replace
,
with
.This is "By Design".
parseFloat
The function only considers parts of the string until it encounters a non- , -, number, exponent, or decimal point. Once it sees the comma, it stops looking and only considers the "75" part.To fix this problem, convert commas to decimal points.