In this JavaScript Tutorial, we will see how to use Math functions pow, min, max. We will also look at round & floor and how they can be used on decimal numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<!DOCTYPE HTML> <HTML> <HEAD> <TITLE>Learn Java Script</TITLE> </HEAD> <BODY> <H1> JavaScript Math Functions </H1> <br/> <script type="text/javascript" > var num1 = 3.467; var num2 = 3.667; document.write("5 Power 2 is =" + Math.pow(5,2) + "</br>"); document.write("The Maximum of (2,9,1,3,6,5) is =" + Math.max(2,9,1,3,6,5) + "</br>"); document.write("The Minimum of (2,9,1,3,6,5) is =" + Math.min(2,9,1,3,6,5) + "</br>"); document.write("Math.round(3.467) =" + Math.round(num1) + "</br>"); document.write("Math.round(3.667) =" + Math.round(num2) + "</br>"); document.write("Math.floor(3.467) =" + Math.floor(num1) + "</br>"); document.write("Math.floor(3.667) =" + Math.floor(num2) + "</br>"); </script> </BODY> </HTML> |
Categories: JavaScript-Tube