How to use Number object in JavaScript

In this article I am going to explain about Number object in JavaScript.
  • 1416

JavaScript Number object

In JavaScript Number object use to converts the object argument in a number that represents the object's . If the value can not be converted to a legal number then its will display NaN. There are several properties and that use in Number object.

Number object properties

  • Constructor - Its return by which create the Number object prototype.
  • MAX VALUE - Its return largest number possible in JavaScript.
  • MIN VALUE - Its return smallest number possible in JavaScript.
  • NEGATIVE INFINITY - Represents negative infinity
  • POSITIVE INFINITY - Represents infinity
  • Prototype - Add properties and method to object.

Number object method

  • toExponential() - Its convert number in exponential notation.
  • toFixed() - Formats a number with x numbers of digits after the decimal point
  • toprecication() - Formats a number to x length
  • toString() - Convert number in string format.
  • valueOff() - Returns the primitive value of a Number object

Example:-

<html>

<head>

    <script type="text/javascript">

        function Myfun() {

            var str1 = new Boolean(true);

            var str2 = new Boolean(false);

            var str3 = new Date();

            var str4 = new String("299");

            var str5 = new String("896 54667");

 

            document.write(Number(str1) + "<br />");

            document.write(Number(str2) + "<br />");

            document.write(Number(str3) + "<br />");

            document.write(Number(str4) + "<br />");

            document.write(Number(str5) + "<br />");

        }

 

    </script>

</head>

<body>

    <button onclick="Myfun()">

        Click</button>

</body>

</html>

 

Output


 number.gif


Further Readings

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.