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

197
Views
I keep getting NaN values in my JQuery code when using the Intl.NumberFormat function

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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!

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