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

176
Views
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
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!