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

177
Visualizações
Why is a numeric value altered when it is appended to the dom with jQuery?

Here is the snippet from a function:

const discountPrice = parseFloat(+(discount[1].trim())).toFixed(2).toString(); //--> 550.47
console.log(`discountPrice: ${discountPrice}`, discount[1], discountPrice); //--> discountPrice: 550.47  550.47 550.47
h += `
    <tr class="discountRow discountrowx">
        <td nowrap>
            <span class="discountDesc" discountId="${discountObj.iddiscount}">${discountType}</span>
        </td>
        <td class="discountPriceDisplay">${discountPrice.toString()}</td> 
        <input type="hidden" class="discountPrice" discountid="${discountObj.iddiscount}" name="DiscountPrice${k}" value="${discountPrice.toString()}">
    </tr>`;
console.log(`now it's:`, discountPrice);

This is what the string looks like after the function. It's perfect:

<tr class="discountRow discountrowx">
    <td nowrap>
        <span class="discountDesc" discountId="6180">Extra 30% off All Sale  (FALLFORKICKEE)</span>
    </td>
    <td class="discountPriceDisplay">550.47</td>
    <input type="hidden" class="discountPrice" discountid="6180" name="DiscountPrice0" value="550.47">
</tr>

Then I append it to the dom:

$(`#tblDiscounts`).append(h);

and get this:

<tr class="discountRow discountrowx">
    <td nowrap="">
        <span class="discountDesc" discountid="6180">Extra 30% off All Sale  (FALLFORKICKEE)</span>
    </td>
    <td class="discountPriceDisplay">550.4699999999997</td>
    <input type="hidden" class="discountPrice" discountid="6180" name="DiscountPrice0" value="550.4699999999997">
</tr>

The dollar value is rounding down somehow.I've tried with and without toString(). I've tried parseFloat-ing it again..nothing works.

about 4 years ago · Juan Pablo Isaza
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