1

enter image description here

I have a bot that needs to display very small conversions in crypto. Currently, when the number is small, the output shows in scientific notation with E. I don't want this notation, how can I format this to display like a normal number

Thanks for your answers in advance. Coded in Node.js

D4RKCIDE
  • 3,439
  • 1
  • 18
  • 34
PirateApp
  • 5,433
  • 4
  • 57
  • 90
  • 1
    Which language are u using? C# or Node? – Ezequiel Jadib Aug 09 '17 at 13:58
  • 2
    See https://stackoverflow.com/questions/1685680/how-to-avoid-scientific-notation-for-large-numbers-in-javascript – richie Aug 09 '17 at 15:13
  • 1
    Possible duplicate of [How to avoid scientific notation for large numbers in JavaScript?](https://stackoverflow.com/questions/1685680/how-to-avoid-scientific-notation-for-large-numbers-in-javascript) – Ezequiel Jadib Aug 09 '17 at 17:27

1 Answers1

3

You can use toFixed() on your number to show the number with the desired precision.

number.toFixed(precision)

Here is an example:

let number = 0.000000635345

number.toFixed(5)    // 0.00000
number.toFixed(6)    // 0.000001
number.toFixed(7)    // 0.0000006
number.toFixed(8)    // 0.00000064

You can use this in in conjunction with a RegExp to remove the trailing zeros:

let number = 0.0000005
number.toFixed(10)                          // 0.0000005000

number.toFixed(10).replace(/\.?0+$/,"")     // 0.0000005
Kayvan Mazaheri
  • 2,447
  • 25
  • 40