Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
jQuery string to number get rounded

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!