JavaScript 数字toPrecision函数


JavaScript 数字toPrecision函数

<html>
   <head>
      <title>JavaScript toPrecision() Method </title>
   </head>

   <body>

      <script type = "text/javascript">
         var num = new Number(7.123456);
         document.write("num.toPrecision() is " + num.toPrecision());
         document.write("<br />");

         document.write("num.toPrecision(4) is " + num.toPrecision(4));
         document.write("<br />");

         document.write("num.toPrecision(2) is " + num.toPrecision(2));
         document.write("<br />");

         document.write("num.toPrecision(1) is " + num.toPrecision(1));
      </script>

   </body>
</html>