-3

Let's say we have the number 300 and I wanted it to be padded to end as 300.000

Or the number 23,5 would be something like 23.500

BryceSoker
  • 624
  • 1
  • 11
  • 29
  • 1
    Does this answer your question? [Add .00 (toFixed) only if number has less than two decimal places](https://stackoverflow.com/questions/24038971/add-00-tofixed-only-if-number-has-less-than-two-decimal-places) – Ismael Padilla Jan 23 '20 at 11:14
  • you can use Numeraljs to paly around the numbers:https://www.npmjs.com/package/numeral – Sandeep Patel Jan 23 '20 at 11:16

1 Answers1

0

Hope it will help, details are in comments.

function formating(n) {
  // Convert number into a String
  const str = n.toString();
  // Find the position of the dot.
  const dotPosition = str.search(/\./);
  // Return string with the pad.
  if (dotPosition === -1) {
    return str += ".000";
  } else {
    const [part1, part2] = str.split('.');
    return part1 + '.' + part2.padEnd(3, "0");
 }
}