My code is here:
https://codepen.io/ron-ratzlaff/pen/NWyaKbq
I am using the following to format values to USD currency:
const moneyFormat = new Intl.NumberFormat("en", {
style: "currency",
currency: "USD",
});
The specific area I am trying to focus on is here:
$(document).ready(function () {
roofCompInput.change(function () {
if (roofCompInput.prop("selectedIndex") == 1) {
roofPriceBeforeItc.val(
moneyFormat.format(
+calcRoofSqftInput.val() * 18 +
2000 * +systemSizeInput.val().replace(" kW", "")
)
);
if (roofPriceBeforeItc.val() !== 0 && pwrWallPriceBeforeItc.val() == 0) {
pwrWallPriceBeforeItc.val(moneyFormat.format(0));
estTotalBeforeItc.val(roofPriceBeforeItc.val());
estItc.val(+estTotalBeforeItc.val() * 0.26);
totalCostInput.val(+estTotalBeforeItc.val() - +estItc.val());
The estItc.val(+estTotalBeforeItc.val() * 0.26); keeps producing a NaN value and that's what I am trying to resolve at the moment.
I think the dollar sign must be the issue, but I am not certain.
When I use the following to try to resolve the issue, I get a $NaN value:
estItc.val(moneyFormat.format(+estTotalBeforeItc.val() * 0.26)); // produces a $NaN value
Any help would be greatly appreciated.
Thank you
Okay, I found the answer.
After using the following code, it fixed my issue.
moneyFormat.format(+estTotalBeforeItc.val().replace(/[^\d\.]/g, '') * 0.26)
Thanks anyway!