toFixed(保留几位小数)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// Number
// toFixed(保留几位小数)
var price = 123.4
var sum = price.toFixed(2)-0+100
console.log(sum.toFixed(2))
</script>
</body>
</html>
Math对象 random返回一个0-1之间的随机数
Math.round()四舍五入取整
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// round四舍五入取整
console.log(Math.round(4.46))
console.log(Math.round(5.56))
</script>
</body>
</html>
Math.ceil()向上取整 Math. floor()向下取整
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// ceil向上 floor向下
console.log(Math.ceil(4.46))
console.log(Math.round(5.56))
</script>
</body>
</html>
abs取绝对值
console.log(Math.abs(-10))
sqrt取平方根
console.log(Math.sqrt(25))
pow(底数,指数)
console.log(Math.pow(2,3)) 相当于2的3次方
min和max
console.log(Math.min(10,2,3,11,50))
console.log(Math.max(10,2,3,11,50))
PI 圆周率
console.log(Math.PI)