how can I format number with at least one decimal in numeraljs

253 Views Asked by At

In numeraljs, I want to do that :

I need has thousand separator, in addition,

if one number has one or more decimal, just print all decimal. How many decimals is not sure.

if one number has no decimal, just add one zero as its decimal.

e.g. I want to format 1234 to 1,234.0 and 1234.4567 to 1,234.4567,

how to do that?

1

There are 1 best solutions below

0
Nikhil Gyan On

Please try this:

var target = 123.4567;
if(target % 1 !== 0) {
    alert(target);
}
else {
  alert(target.toFixed(1));
}