-6

How do you format the numbers that result in total of 12 digits?

12.123 should result 12.1230000000
1234567890.12345 should result 1234567890.12
12 should result 12.0000000000
Barmar
  • 741,623
  • 53
  • 500
  • 612
Navin Rauniyar
  • 10,127
  • 14
  • 45
  • 68

1 Answers1

1

Number.prototype.toPrecision()

Fiddle Demo

function FormatMeTo12Digits(num) {
    return num.toPrecision(12);
}

FormatMeTo12Digits(12.345);
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107