JavaScript 数字toFixed函数


JavaScript 数字toFixed函数

<html>
   <head>
      <title>JavaScript toFixed() Method</title>
   </head>
   <body>

      <script type = "text/javascript">
         var num = 177.1234;
         document.write("num.toFixed() is : " + num.toFixed());
         document.write("<br />");

         document.write("num.toFixed(6) is : " + num.toFixed(6));
         document.write("<br />");

         document.write("num.toFixed(1) is : " + num.toFixed(1));
         document.write("<br />");

         document.write("(1.23e+20).toFixed(2) is:" + (1.23e+20).toFixed(2));
         document.write("<br />");

         document.write("(1.23e-10).toFixed(2) is : " + (1.23e-10).toFixed(2));
      </script>

   </body>
</html>