1

I got a list with prices inside and I want to get these (in this example one) to use them later for a calculation.

My idea was to get it as a string, convert it to a decimal and then do my calculation with it. The other idea would be to get the string and remove the   and the but I think the conversion into a number is better, isn't it?

 paidNettoWithShipping = parseFloat($('.aggregation--list .entry--totalnet .entry--value').text()).toFixed(2);

 console.log(paidNettoWithShipping);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="aggregation--list">
  <div class="entry--totalnet">
    <div class="entry--value">21,01&nbsp;€</div>
  </div>
</div>

The problem here is, that my numbers gets rounded to 21.00 instead of the correct 21.01 is this because of the , instead of . in my html? Thats how we write currency in europe, so I won't change that.

How do I get my correct number to use it later in some calculations?

That's what I see in the console. My Result

skarpeta
  • 105
  • 6

1 Answers1

0

As suggested by @CBroe, by using replace() you can achieve it:

 paidNettoWithShipping = parseFloat($('.aggregation--list .entry--totalnet .entry--value').text().replace(',', '.')).toFixed(2);

 console.log(paidNettoWithShipping);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="aggregation--list">
  <div class="entry--totalnet">
    <div class="entry--value">21,01&nbsp;€</div>
  </div>
</div>
gcpdev
  • 442
  • 6
  • 20