toFixed方法保留小数位数

<!DOCTYPE html>
<html>
    <head>
<meta charset="UTF-8">

    </head>
    <body>
        <script>
//  toFixed方法
//  1.作用:对数据进行小数位数的保留
//  2.格式:数据.toFixed(小数位数)
// 3.返回值:返回值是字符串类型

var a = 3.1425926;
var b = a.toFixed(3);
console.log(b);
console.log(typeof b);

        </script>
    </body>
</html>

猜你喜欢

转载自www.cnblogs.com/1998Archer/p/12586687.html