zoukankan      html  css  js  c++  java
  • JavaScript 21 Math

    Math是JavaScript的工具对象,用于常见的数学运算

    步骤 1 : 

    自然对数和圆周率

    属性E PI,分别表示自然对数和圆周率PI

    <script>
     
    document.write(Math.E);
    document.write("<br>");
    document.write(Math.PI);
    </script>

     步骤 2 : 

    绝对值

    <script>
    document.write(Math.abs(-1));
    </script>

    步骤 3 : 

    最小最大

    <script>
    document.write(Math.min(1,100));
    document.write("<br>");
    document.write(Math.max(1,100));
    </script>

    步骤 4 : 

    求幂

    方法 pow 求一个数的n次方

    <script>
    document.write(Math.pow(3,3)); //3的立方,即27
    </script>

    步骤 5 : 

    四舍五入

    <script>
    document.write(Math.round(3.4));
    document.write("<br>");
    document.write(Math.round(3.5));
    </script>

    步骤 6 : 

    随机数

    方法 random 取0-1之间的随机数

    <script>
    document.write("一个 0-1 之间的随机数 : Math.random():");
    document.write("<br>");
    document.write(Math.random());
    document.write("<br>");
    document.write("十个 5-10 之间的随机数 : Math.round(Math.random() *5)+5 ");
    document.write("<br>");
    for(i=0;i<10;i++){
    document.write(Math.round(Math.random() *5)+5 ); //5-10之间的随机整数
    document.write("<br>");
    }
    </script>


  • 相关阅读:
    数组与方法
    数据类型
    认识Java(2)
    认识Java(1)
    面试题集锦
    00-python语言介绍
    06-python-生成器、循环器
    00-python-内置函数笔记
    04-python-闭包
    03-python-装饰器
  • 原文地址:https://www.cnblogs.com/JasperZhao/p/13369923.html
Copyright © 2011-2022 走看看