国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Number numerical object in JavaScript

Number numerical object

A numerical variable is a numerical object (Number object).



##toFixed()

  • Function: Change a value Convert to a string and round, retaining the specified number of decimal places.

  • Syntax: numObj.toFixed(n)

  • Parameters: n is the number of decimal places to be retained.

  • Example:

var a = 123.9878;

a = a.toFixed(2); // a = “123.99”

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script>
            var x=134.456756;
            document.write(x.toFixed(3));
        </script>
    </head>
    <body>
    </body>
</html>

Example: Find the area of ??a circle

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script>
            //求圓的面積
            function getArea(r){
                var s=Math.PI*r*r;
                s=s.toFixed(4);
                document.write("半徑為:"+r+"的圓,面積為:"+s+"<br/>");
            }
            getArea(2);
            getArea(4);
            getArea(5);
        </script>
    </head>
    <body>
    </body>
</html>

##

Continuing Learning
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> var x=134.456756; document.write(x.toFixed(3)); </script> </head> <body> </body> </html>
submitReset Code