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

295
Views
Check if a const of type number is invalid except 0

I'm checking a number if its null, undefined,..except 0/0.0/0.00 then display value in UI, as shown in below:

const currencyFormat = (num) => {
  if(!num) {     // should be true for all cases except 0
    return "0.00"
  }
  return "$"+ num;
}

in render :
 {num === null && <div>
     <h1> {currencyFormat(num)} </h1>
  </div>}

How can I display 0/0.0/0.00 because if !num is also true for 0?

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

0

Maybe you can try something like:

const currencyFormat = (num) => {
  const number = parseInt(num);
  if(isNaN(number)) // return whatever you want in case when invalid number(or no number at all)
  if(number === 0) return "0.00";

  return "$"+ num;
}
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!