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>

  • 相关阅读:
    YCSB测试Mysql,MongoDB,TokuMX,Couchbase性能
    使用FIO对SATA、SSD和PCIe Flash进行测试
    使用jenkins实现持续集成
    linux服务器性能(网卡流量、CPU、内存、磁盘使用率)监控
    Linux下Hadoop2.7.1集群环境的搭建(超详细版)
    10分钟学会js处理json常用方法
    springboot:Java模板引擎Thymeleaf介绍
    springboot使用遇到问题:Class “model.Address” is listed in the persistence.xml file but not mapped
    eclipse4.6.1安装SpringSource Tool Suite(sts-eclipse)插件
    由一条sql语句想到的子查询优化
  • 原文地址:https://www.cnblogs.com/padding1015/p/5853516.html
Copyright © 2011-2022 走看看