Aquí está el fragmento de una función:
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);Así es como se ve la cadena después de la función. Es perfecto:
<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>Luego lo agrego al dom:
$(`#tblDiscounts`).append(h);y consigue esto:
<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>El valor en dólares se está redondeando hacia abajo de alguna manera. Lo he intentado con y sin toString(). He intentado parseFloat-ing de nuevo... nada funciona.