I am using a .
as a thousands separator.
So the string 128.814
should be read as "one hundred and twenty eight thousand, eight hundred and fourteen".
When I add this to the number 900, I want the answer to be 129714 (displayed as 129.714
).
However, because javascript takes the thousands separator as a decimal point, it's giving me an undesirable result.
function addTotalPrice(item){
var priceItem = parseFloat( $(item).find('.price').text() );
var priceTotal = parseFloat( $('.label-price span').text() );
var result = (priceTotal + priceItem);
$('.label-price span').text( result.toFixed(3) );
}
How can I tell jQuery/Javascript to interpret the .
in 128.814
as a thousands separator and not a decimal point?
Simplest way would be to remove it.
When you remove it, it will automatically be interpreted as a thousands value, even without the comma there. Then, manually format the number like in How to print a number with commas as thousands separators in JavaScript