[javascript] How to avoid scientific notation for large numbers in JavaScript?

function printInt(n) { return n.toPrecision(100).replace(/\..*/,""); }

with some issues:

  • 0.9 is displayed as "0"
  • -0.9 is displayed as "-0"
  • 1e100 is displayed as "1"
  • works only for numbers up to ~1e99 => use other constant for greater numbers; or smaller for optimization.