Web ScriptoPlanet()

# JavaScript Number Object These tutorials introduce the Number object. Number is the data type JavaScript uses to hold numerical values. Unlike "strongly-typed" languages, JavaScript uses a single data type to represent all kinds of numerical values, like integers of all sizes, floating points, fractions…

The JavaScript Math object is different from the Number object. The number object is used to hold numerical values in JavaScript. The Math object is used to perform operations on numerical values.

## Types of Numbers in JavaScript

The single Number data type is used in JavaScript to represent any kind of numerical value. Unlike "strongly typed" programming language, JavaScript does not create a distinction between small integers, large integers, and floating points. The JavaScript interpreter considers all these simply as "Number".

Below, three types of numbers are declared:

`// Declare a positive integervar numex1 = 1;// declare a negative integervar numex2 = -47;// declare a floating point numbervar numex3 = 3.14;alert( numex2.toString() +"\n"+ numex3.toString() );`

The last line of our script displays the last two numbers we declared, separated by the new line character ("\n") for clarity: We used the toString() method to convert to a string each number passed to the alert() method.

## JavaScript Number Properties

We will cover the properties available to JavaScript Numbers. The properties below have a constant value, which cannot be changed by your scripts.

## JavaScript Number Methods

Our tutorials will cover the most common JavaScript number methods. Methods are special functions available to different types of objects; like other objects, JavaScript numbers have numerous manipulation and conversion methods.

• The toString() method returns a string representation of the number.
• The toFixed() method converts a number to a string with a specificied number of digits after the decimal point.
• The toExponential() method returns a string representation of the number in exponential notation.
• The toPrecision() method returns a string representation of the number using decimal or exponential notation (depending number size and precision requested.)

## Number-related Functions

We will also cover common functions, part of the core JavaScript language, which do not actually belong to the Number object, but which are used in conjunction with Number objects.