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

The following solution bypasses the automatic exponentional formatting for very big and very small numbers. This is outis's solution with a bugfix: It was not working for very small negative numbers.

_x000D_
_x000D_
function numberToString(num)_x000D_
{_x000D_
    let numStr = String(num);_x000D_
_x000D_
    if (Math.abs(num) < 1.0)_x000D_
    {_x000D_
        let e = parseInt(num.toString().split('e-')[1]);_x000D_
        if (e)_x000D_
        {_x000D_
            let negative = num < 0;_x000D_
            if (negative) num *= -1_x000D_
            num *= Math.pow(10, e - 1);_x000D_
            numStr = '0.' + (new Array(e)).join('0') + num.toString().substring(2);_x000D_
            if (negative) numStr = "-" + numStr;_x000D_
        }_x000D_
    }_x000D_
    else_x000D_
    {_x000D_
        let e = parseInt(num.toString().split('+')[1]);_x000D_
        if (e > 20)_x000D_
        {_x000D_
            e -= 20;_x000D_
            num /= Math.pow(10, e);_x000D_
            numStr = num.toString() + (new Array(e + 1)).join('0');_x000D_
        }_x000D_
    }_x000D_
_x000D_
    return numStr;_x000D_
}_x000D_
_x000D_
// testing ..._x000D_
console.log(numberToString(+0.0000000000000000001));_x000D_
console.log(numberToString(-0.0000000000000000001));_x000D_
console.log(numberToString(+314564649798762418795));_x000D_
console.log(numberToString(-314564649798762418795));
_x000D_
_x000D_
_x000D_