zoukankan      html  css  js  c++  java
  • JS-Math对象

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Math对象练习</title>
    </head>
    <body>
    <h1>Math属性代码验证</h1>
    <input type="button" value="点击" onclick="a()"/><br/>
    <span id="x"></span>
    <script type="text/javascript">
    var x = document.getElementById('x');
    function a(){
    x.innerHTML = Math.E + '——返回算数常量e,即自然对数的底数。<br/>' +Math.LN2 +'——返回2的自然对数<br/>'+Math.LN10+'——返回10的自然对数<br/>'+Math.LOG2E+'——返回以2为底的e的对数<br/>'+Math.LOG10E+'——返回以10为底的e的对数<br/>'+Math.PI+'——返回圆周率<br/>'+Math.SQRT1_2+'——返回2的平方根的倒数<br/>'+ Math.SQRT2 + '——返回2的平方根';
    }//这里很奇怪的是,如果id为x的容器表现是textarea的话,换行符需要用 才管用,换成了p、span、a等标签,用<br />就可以了
    </script>
    <h1>Math方法代码验证</h1>
    <h3>ceil(x)向上舍入</h3>
    <script type="text/javascript">
    document.write('0.3向上取舍变成》》'+Math.ceil(0.3)+'<br />');
    document.write('0.9》》'+Math.ceil(0.9)+'<br />');
    document.write('6.3》》'+Math.ceil(6.3)+'<br />');
    document.write('5》》'+Math.ceil(5)+'<br />');
    document.write('3.5》》'+Math.ceil(3.5)+'<br />');
    document.write('-5.1》》'+Math.ceil(-5.1)+'<br />');
    document.write('-5.9》》'+Math.ceil(-5.9)+'<br />');
    </script>
    <h3>floor(x)向下舍入</h3>
    <script type="text/javascript">
    document.write('0.3向下取舍变成》》'+Math.floor(0.3)+'<br />');
    document.write('0.9》》'+Math.floor(0.9)+'<br />');
    document.write('6.3》》'+Math.floor(6.3)+'<br />');
    document.write('5》》'+Math.floor(5)+'<br />');
    document.write('3.5》》'+Math.floor(3.5)+'<br />');
    document.write('-5.1》》'+Math.floor(-5.1)+'<br />');
    document.write('-5.9》》'+Math.floor(-5.9)+'<br />');
    </script>
    <h3>round(x)四舍五入</h3>
    <script type="text/javascript">
    document.write('0.3四舍五入变成》》'+Math.round(0.3)+'<br />');
    document.write('0.9》》'+Math.round(0.9)+'<br />');
    document.write('6.3》》'+Math.round(6.3)+'<br />');
    document.write('5》》'+Math.round(5)+'<br />');
    document.write('3.5》》'+Math.round(3.5)+'对于0.5,进行上舍入<br />');
    document.write('-5.1》》'+Math.round(-5.1)+'<br />');
    document.write('-5.9》》'+Math.round(-5.9)+'<br />');
    document.write('-5.5》》'+Math.round(-5.5)+'若两边相同接近,则结果接近x轴正方向的正无穷方向<br />');
    document.write('-5.52》》'+Math.round(-5.52)+'<br />');
    </script>
    </body>
    </html>

  • 相关阅读:
    zabbix 监控机器监听的端口 + 触发器 表达式理解
    php关于文件上传的两个配置项说明
    linux cron计划任务防止多个任务同时运行
    php注册自动加载函数
    linux 下查看机器是cpu是几核的
    laravel容器类make方法解释
    laravel php门面模式
    js获取当前页面的url地址
    php编码规范
    laravel console handle 传参方法
  • 原文地址:https://www.cnblogs.com/padding1015/p/5853516.html
Copyright © 2011-2022 走看看