Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda