SOURCE

/**
 * 获取坐标轴间隔
 * 16666 -> 4000
 */
const formatNumber = function (num, step = 4) {
    const isNegative = num < 0
    num = 'number' == typeof num ? Math.abs(num) : Math.abs(Number(num))
    var r, o, s
    if (0 == num || 1 == num) {
        return num * (isNegative ? -1 : 1)
    }
    if (num < 1) {
        s = num.toString().split('.')[1].length
        o = num * Math.pow(10, s)
        return n.formatNumber(isNegative ? -1 * o : o, step) / Math.pow(10, s)
    }

    if (num < 4) {
        if (t) {
            s = num !== Math.ceil(num) ? num.toString().split('.')[1].length : 1;
            o = num * Math.pow(10, s);
            return n.formatNumber(isNegative ? -1 * o : o, step) / Math.pow(10, s)
        }

        r = Math.ceil(num)
    } else {
        s = Math.floor(num).toString().length
        o = s > 1 ? step * Math.pow(10, s - 2) : step
        r = (o * Math.pow(10, s) * Math.ceil(num / o)) / Math.pow(10, s)
    }


    return r * (isNegative ? -1 : 1)
}



console.log(formatNumber(-14887, 5))

console 命令行工具 X clear

                    
>
console