目录

toPrecision()

此方法将表示数字对象的字符串返回到指定的精度。

语法 (Syntax)

number.toPrecision( [ precision ] ) 

参数的细节 (Parameter Details)

  • precision - 指定有效位数的整数。

返回值 (Return Value)

返回表示固定点或指数表示法舍入有效数字的Number对象的字符串。

例子 (Example)

var num = new Number(7.123456); 
console.log(num.toPrecision()); 
console.log(num.toPrecision(1)); 
console.log(num.toPrecision(2));

输出 (Output)

7.123456 
7 
7.1  
↑回到顶部↑
WIKI教程 @2018