💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] ## Number 对象 * `Number.POSITIVE_INFINITY`:正的无限,指向`Infinity`。 * `Number.NEGATIVE_INFINITY`:负的无限,指向`-Infinity`。 * `Number.NaN`:表示非数值,指向`NaN`。 * `Number.MIN_VALUE`:表示最小的正数(即最接近0的正数,在64位浮点数体系中为`5e-324`), 相应的,最接近0的负数为`-Number.MIN_VALUE`。 * `Number.MAX_SAFE_INTEGER`:表示能够精确表示的最大整数,即`9007199254740991`。 * `Number.MIN_SAFE_INTEGER`:表示能够精确表示的最小整数,即`-9007199254740991`。 ## 实例方法 ### Number.prototype.toFixed() 保留小数 ``` 100.2253.toFixed(2)) // 100.23 四舍五入,返回字符串 Number(100.2253.toFixed(2))) //返回浮点 ``` ### Number.prototype.toExponential() 转为科学计数法 ``` (10).toExponential() // "1e+1" (10).toExponential(1) // "1.0e+1" (10).toExponential(2) // "1.00e+1" (1234).toExponential() // "1.234e+3" (1234).toExponential(1) // "1.2e+3" (1234).toExponential(2) // "1.23e+3" ``` ### Number.prototype.toPrecision() 指定位数的有效数字 ``` (12.34).toPrecision(1) // "1e+1" (12.34).toPrecision(2) // "12" (12.34).toPrecision(3) // "12.3" (12.34).toPrecision(4) // "12.34" (12.34).toPrecision(5) // "12.340" ``` ### 自定义方法 ``` Number.prototype.add=function (x) { return this+x } //调用方式一 var a =8; a.add(4); //12 //调用方式二 8['add'](4); //12 //调用方式三 (8).add(4); //12 a;//8 ```