Javatpoint Logo
Javatpoint Logo

TypeScript Numbers

Like JavaScript, all the numbers in TypeScript are stored as floating-point values. These numeric values are treated like a number data type. The number is used to represents both integers as well as floating-point values. The number type converts the numeric literal to an instance of the number class. The number class acts as a wrapper and manipulate the numeric literals as they were objects. TypeScript also supports Binary(Base 2), Octal(Base 8), Decimal(Base 10), and Hexadecimal(Base 16) literals.

Syntax

Example


Number Properties

The Number objects have the following set of properties:

SN Property_Name Description
1. MAX_VALUE It returns the largest possible value of a number in JavaScript and can have 1.7976931348623157E+308.
2. MIN_VALUE It returns the smallest possible value of a number in JavaScript and can have 5E-324.
3. NEGATIVE_INFINITY It returns a value that is less than MIN_VALUE.
4. POSITIVE_INFINITY It returns a value that is greater than MAX_VALUE.
5. NaN When some number calculation is not representable by a valid number, then TypeScript returns a value NaN. It is equal to a value that is not a number.
6. prototype It is a static property of the Number object. It is used to assign new properties and methods to the Number object in the current document.

Example

Output:

Number Properties: 
A number variable can hold maximum value: 1.7976931348623157e+308
A number variable can hold minimum value: 5e-324
Value of Negative Infinity: -Infinity
Value of Positive Infinity: Infinity
Example of NaN: NaN

Number Methods

The list of Number methods with their description is given below.

SN Method_Name Description
1. toExponential() It is used to return the exponential notation in string format.
2. toFixed() It is used to return the fixed-point notation in string format.
3. toLocaleString() It is used to convert the number into a local specific representation of the number.
4. toPrecision() It is used to return the string representation in exponential or fixed-point to the specified precision.
5. toString() It is used to return the string representation of the number in the specified base.
6. valueOf() It is used to return the primitive value of the number.

Example

Output:

Number Method: toExponential()
1.2345e+4
1.23e+4
Number Method: toString()
12345
3000321
Number Method: toFixed()
13
12.879
Number Method: toLocaleString()
12,667.976
Number Method: toPrecision()
1e+1
12.6
Number Method: tovalueOf()
[Number: 123]
123
number





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA