-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy path37_number.js
35 lines (20 loc) · 1.48 KB
/
37_number.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// In JavaScript, the Number object is a built -in object that represents numerical values.It provides methods for performing mathematical operations on numbers, as well as for formatting and manipulating numbers.
// Here are some of the most commonly used methods of the Number object in JavaScript:
// Number() : Converts a string or a variable to a number.
// Number.MAX_VALUE : Returns the largest possible number in JavaScript.
// Number.MIN_VALUE : Returns the smallest possible number in JavaScript.
// Number.NaN : Represents a value that is not a number.
// Number.isNaN(x) : Returns true if x is NaN, and false otherwise.
// Number.parseFloat(str) : Converts a string to a floating - point number.
// Number.parseInt(str) : Converts a string to an integer.
// Number.prototype.toFixed(num) : Formats a number with a fixed number of decimal places.
// Number.prototype.toPrecision(num) : Formats a number with a specified precision.
// Number.prototype.toString(radix) : Converts a number to a string, using the specified radix(base).
// Here is an example of how to use some of these Number object methods in JavaScript:
// let num1 = Number("123");
// let num2 = 123.456;
// console.log(num1); // 123
// console.log(num2.toFixed(2)); // 123.46
// console.log(num2.toPrecision(3)); // 123
// console.log(num2.toString(2)); // 1111011.01110110011001100110011001100110011001100110011010
// By using the Number object and its methods, you can easily work with numerical values in JavaScript.