Begin Web Programming with PHP & MySQL

Advertisements



JavaScript Number Object

The Number object allows us to work with numerical values. The Number object is created using the Number() constructor.
Syntax:
var num = new Number(value);
Here, if the value cannot convert to a number, it returns NaN(Not a Number).

Properties of Number Object
Property Description
MAX_VALUE It returns the largest value representable in JavaScript. Values above MAX_VALUE are represented as Infinity.
MIN_VALUE It returns the smallest positive value representable in JavaScript. Numbers smaller than this are converted to 0.
POSITIVE_INFINITY Positive infinity value.
NEGATIVE_INFINITY It returns negative infinity
NaN It represents Not a Number value.
prototype In JavaScript, every object has a property named prototype by default. It allows us to add new properties and methods to a Number object.
Methods of Number Object
Method Description
isInteger() It checks whether the passed value is an integer or not.
isNaN() It checks whether the passed value is not a number.
toExponential() It converts a number to an exponential format.
toString() It converts a number to a string.
toFixed() The toFixed() method rounds the string to a specified number of decimals.
toPrecision() The toPrecision() method formats a number to a specified length.
valueOf() The valueOf() method returns the primitive value of a string.
Number() The Number() method converts a value to a number. If the value cannot be converted, NaN is returned.
parseInt() The parseInt() function parses a string argument and returns an integer
parseFloat() The parseFloat() function parses an argument and returns a floating point number.