Working With Number Object Using JavaScript

All the numbers in JavaScript are 64 bit (8 byte) floating point numbers, which yield an effective range of 5e-324(negative) to 1.7976931348623157e+308 (positive). Unlike c or c++, there are no data types such as integer or float, to define numbers in JavaScript. The syntax for creating number object is:

Syntax:

Var num=new Number(value);

Demo:

  1. Let us create a document named NumberTest.html.

    Noteoad

  2. Write the following code:
    1. <!DOCTYPE HTML>  
    2.   
    3. <head>  
    4.     <title>Number Test</title>  
    5. </head>  
    6.   
    7. <body>  
    8.     <script type="text/javascript">  
    9.     var num = new Number('15.603);  
    10.             document.write(num.toExponential() + "<br>"); document.write(num.toFixed() + "<br>"); document.write(num.toPrecision(3) + "<br>"); document.write(num.toString() + "<br>"); document.write(num.valueOf() + "<br>");  
    11.     </script>  
    12. </body>  
    13.   
    14. </html>  
  3. Execute the script by Opening the file in the Web Browser. If you are using Internet Explore click on “Allow Blocked Content” to allow the script to execute and you are using Mozilla Firefox then click on allow “ActiveX Controls”.

    Output