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?
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;
}