javascript 保留两位有效数字

来源:互联网 发布:java函数返回值为数组 编辑:程序博客网 时间:2024/04/30 19:34
<!DOCTYPE html><html>  <head>    <title>testDigit.html</title>    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">    <meta http-equiv="description" content="this is my page">    <meta http-equiv="content-type" content="text/html; charset=UTF-8">        <!--<link rel="stylesheet" type="text/css" href="./styles.css">--><script type="text/javascript">  function ForDight(Dight,How){              Dight = Math.round(Dight*Math.pow(10,How))/Math.pow(10,How);              return Dight;          }          function f2(){       alert(ForDight(12345.67890,2));//保留三位小数            alert(ForDight(123.99999,2));//保留四位小数        }      </script>  </head>    <body>    <input type="button" value="四舍五入" onclick="f2()"/>  </body></html>

原创粉丝点击