Math objects commonly used in JavaScript

Common mathematical calculations: random numbers from 0 to 1, rounding, square root, exponentiation, maximum value, minimum value, etc.


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript string Math对象</title>
</head>
<body>

<script>	
document.write("<br>随机数:" + Math.random() + "<br>");
document.write("<br>PI:" + Math.PI + "<br>");
document.write("<br>absolute value: the absolute value of -11 is " + Math.abs(-11) + "<br>");
document.write("<br>Round-up: 2.25 rounded up is " + Math.ceil(2.25) + "<br>");
document.write("<br>Round-down: 2.88 rounded down is " + Math.floor(2.88) + "<br>");
document.write("<br>Rounding - nearest integer: 3.21 The nearest integer is " + Math.round(3.21) + "<br>");	
document.write("<br>Round to nearest integer: 3.81:" + Math.round(3.81) + "<br>");
document.write("<br>冪:4的2次冪是" + Math.pow(4,2) + "<br>");
document.write("<br>Square root: The square root of 4 is " + Math.sqrt(4) + "<br>");
document.write("<br>Maximum value: The maximum value of 3,4,5,6,8,2 is " + Math.max(3,4,5,6,8,2) + "<br> ");
document.write("<br>Minimum: The minimum value of 3,4,5,6,8,2 is " + Math.min(3,4,5,6,8,2) + "<br>" );
	
</script>

</body>
</html>


Random number: 0.18853684748883937

PI:3.141592653589793

Absolute value: The absolute value of -11 is 11

Rounding up - rounding up: 2.25 rounding up is 3

Rounding up - rounding down: 2.88 rounding down is 2

Rounding - nearest whole number: 3.21 The nearest whole number is 3

Rounding - nearest whole number: 3.81:4

Power: 4 to the power of 2 is 16

Square root: The square root of 4 is 2

Maximum value: 3,4,5,6,8,2 the maximum value is 8

Minimum value: 3,4,5,6,8,2 the minimum value is 2


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325815435&siteId=291194637
Recommended