1

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?

frank
  • 1,169
  • 18
  • 43

1 Answers1

0

Please try this:

var target = 123.4567;
if(target % 1 !== 0) {
    alert(target);
}
else {
  alert(target.toFixed(1));
}
Nikhil Gyan
  • 682
  • 9
  • 16