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:
- Let us create a document named NumberTest.html.
- Write the following code:
- <!DOCTYPE HTML>
-
- <head>
- <title>Number Test</title>
- </head>
-
- <body>
- <script type="text/javascript">
- var num = new Number('15.603);
- 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>");
- </script>
- </body>
-
- </html>
- 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”.