Linked Questions

Popular Questions

When adding values on jquery i get infinte number

Asked by At

I want to make a simple addition of every span with the class .part-price, but when I do it comes out in infinite numbers.

This is my javascript (jquery) :

var total = 0;
  $(".part-price").each(function() {
    total += Number($(this).text());
  });
  $("#cart-total").text(total);

And this is my html :

<span class="part-price">0.86</span>
<span class="part-price">1.00</span>
<span>Total: </span><span id="cart-total">0</span>

At the moment I only have 2 value, one is 0.86, and the other is 1.00, it should come out as:

0.86 + 1.00 = 1.86

But with my code the result is:

0.86 + 1.00 = 1.8599999999999999

Related Questions