JavaScript Number Methods

Now, we will use Number methods such as toString(), toExponential(), toPrecision(), isInteger(), and toLocaleString() method. Let’s see the examples of these Number methods.

Javascript
let x = 21
console.log(x.toString());
console.log(x.toExponential());
console.log(x.toPrecision(4));
console.log(Number.isInteger(x));
console.log(x.toLocaleString("bn-BD"));

Output:

21
2.1e+1
21.00
true
২১

JavaScript Numbers

JavaScript Numbers are primitive data types. Unlike other programming languages, you don’t need int, float, etc. to declare different numeric values. JavaScript numbers are always stored in double-precision 64-bit binary format IEEE 754. 

This format stores numbers in 64 bits, 

  • 0-51 bit stores value(fraction)
  • 52-62 bit stores exponent
  • 63-bit stores sign

Similar Reads

Numeric Types in JavaScript

In JavaScript, numbers play an important role, and understanding their behavior is essential for effective programming. Let’s explore the various aspects of numeric types in JavaScript....

Number Literals:

The types of number literals You can use decimal, binary, octal, and hexadecimal....

Number Coercion in JavaScript

In JavaScript, coercion refers to the automatic or implicit conversion of values from one data type to another. When different types of operators are applied to values, JavaScript performs type coercion to ensure that the operation can proceed. Let’s explore some common examples of coercion:...

JavaScript Number Methods

Now, we will use Number methods such as toString(), toExponential(), toPrecision(), isInteger(), and toLocaleString() method. Let’s see the examples of these Number methods....

Some Facts About Numbers in JavaScript:

String Concatenation with Numbers: When you add a string and a number in JavaScript, the result will be a string concatenation.Javascript numbers which are primarily primitive values can also be defined as objects using a new keyword.Constants preceded by 0x are interpreted as hexadecimal in JavaScript.   Javascript numbers are of base 10 by default, but we can use the toString() method to get output in the required base from base 2 to base 36.Apart from regular numbers, Javascript has BigInt numbers which are integers of arbitrary length....