Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda