0

I have the following code:

    window.total = 0;
    $('.amount').each(function(){       
        if($(this).val()){
        window.total += parseFloat( $.trim($(this).val()).replace(',',''));
        }               
    });
    console.log(window.total);

for this example, there is only one input with the class .amount (there can be many), when the user enters a number with 7 digits and 2 decimal points, the above code cuts the number down to 4 digits.

Anything less then 7 digits it works fine. Any ideas why this is happening?

Js Fiddle : Demo

Sherali Turdiyev
  • 1,745
  • 16
  • 29
user1634781
  • 91
  • 10

1 Answers1

0

In this case, you should use "xxx,xxx,xxx.xx".replace(/,/g, '');. It will work Demo.

Also, you can see this answer: https://stackoverflow.com/a/6052630/4365315

Community
  • 1
  • 1
Sherali Turdiyev
  • 1,745
  • 16
  • 29