溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

JavaScript常見的Number對象有哪些

發布時間:2022-07-11 10:19:17 來源:億速云 閱讀:170 作者:iii 欄目:web開發

JavaScript常見的Number對象有哪些

在JavaScript中,Number對象是用于表示數字的包裝對象。它提供了許多有用的方法和屬性,用于處理數字。本文將介紹一些常見的Number對象及其用法。

1. Number.MAX_VALUE

Number.MAX_VALUE表示JavaScript中可表示的最大正數。它的值約為1.7976931348623157e+308。如果計算結果超過這個值,JavaScript會返回Infinity。

console.log(Number.MAX_VALUE); // 1.7976931348623157e+308

2. Number.MIN_VALUE

Number.MIN_VALUE表示JavaScript中可表示的最小正數。它的值約為5e-324。如果計算結果小于這個值,JavaScript會返回0。

console.log(Number.MIN_VALUE); // 5e-324

3. Number.NaN

Number.NaN表示“非數字”(Not-a-Number)。它是一個特殊的值,用于表示一個無效的數學運算結果。

console.log(Number.NaN); // NaN

4. Number.POSITIVE_INFINITY

Number.POSITIVE_INFINITY表示正無窮大。當計算結果超過Number.MAX_VALUE時,JavaScript會返回這個值。

console.log(Number.POSITIVE_INFINITY); // Infinity

5. Number.NEGATIVE_INFINITY

Number.NEGATIVE_INFINITY表示負無窮大。當計算結果小于-Number.MAX_VALUE時,JavaScript會返回這個值。

console.log(Number.NEGATIVE_INFINITY); // -Infinity

6. Number.isNaN()

Number.isNaN()方法用于判斷一個值是否為NaN。與全局的isNaN()函數不同,Number.isNaN()不會將參數轉換為數字,只有在參數確實是NaN時才會返回true。

console.log(Number.isNaN(NaN)); // true
console.log(Number.isNaN("Hello")); // false

7. Number.isFinite()

Number.isFinite()方法用于判斷一個值是否為有限數。與全局的isFinite()函數不同,Number.isFinite()不會將參數轉換為數字,只有在參數確實是有限數時才會返回true。

console.log(Number.isFinite(42)); // true
console.log(Number.isFinite(Infinity)); // false

8. Number.parseInt()

Number.parseInt()方法用于將字符串轉換為整數。它與全局的parseInt()函數相同。

console.log(Number.parseInt("42")); // 42
console.log(Number.parseInt("42.5")); // 42

9. Number.parseFloat()

Number.parseFloat()方法用于將字符串轉換為浮點數。它與全局的parseFloat()函數相同。

console.log(Number.parseFloat("42.5")); // 42.5
console.log(Number.parseFloat("42")); // 42

10. Number.prototype.toFixed()

toFixed()方法用于將數字轉換為字符串,并保留指定的小數位數。

let num = 42.567;
console.log(num.toFixed(2)); // "42.57"

11. Number.prototype.toPrecision()

toPrecision()方法用于將數字轉換為字符串,并保留指定的有效數字位數。

let num = 42.567;
console.log(num.toPrecision(4)); // "42.57"

12. Number.prototype.toString()

toString()方法用于將數字轉換為字符串??梢灾付ɑ鶖担?到36之間的整數),表示將數字轉換為指定進制的字符串。

let num = 42;
console.log(num.toString(2)); // "101010"
console.log(num.toString(16)); // "2a"

13. Number.prototype.valueOf()

valueOf()方法返回Number對象的原始值。

let num = new Number(42);
console.log(num.valueOf()); // 42

14. Number.prototype.toExponential()

toExponential()方法用于將數字轉換為指數形式的字符串。

let num = 42.567;
console.log(num.toExponential(2)); // "4.26e+1"

15. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

16. Number.prototype.isInteger()

Number.isInteger()方法用于判斷一個值是否為整數。

console.log(Number.isInteger(42)); // true
console.log(Number.isInteger(42.5)); // false

17. Number.prototype.isSafeInteger()

Number.isSafeInteger()方法用于判斷一個值是否為安全整數。安全整數是指能夠精確表示為IEEE-754雙精度浮點數的整數。

console.log(Number.isSafeInteger(42)); // true
console.log(Number.isSafeInteger(9007199254740992)); // false

18. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

19. Number.prototype.toPrecision()

toPrecision()方法用于將數字轉換為字符串,并保留指定的有效數字位數。

let num = 42.567;
console.log(num.toPrecision(4)); // "42.57"

20. Number.prototype.toString()

toString()方法用于將數字轉換為字符串??梢灾付ɑ鶖担?到36之間的整數),表示將數字轉換為指定進制的字符串。

let num = 42;
console.log(num.toString(2)); // "101010"
console.log(num.toString(16)); // "2a"

21. Number.prototype.valueOf()

valueOf()方法返回Number對象的原始值。

let num = new Number(42);
console.log(num.valueOf()); // 42

22. Number.prototype.toExponential()

toExponential()方法用于將數字轉換為指數形式的字符串。

let num = 42.567;
console.log(num.toExponential(2)); // "4.26e+1"

23. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

24. Number.prototype.isInteger()

Number.isInteger()方法用于判斷一個值是否為整數。

console.log(Number.isInteger(42)); // true
console.log(Number.isInteger(42.5)); // false

25. Number.prototype.isSafeInteger()

Number.isSafeInteger()方法用于判斷一個值是否為安全整數。安全整數是指能夠精確表示為IEEE-754雙精度浮點數的整數。

console.log(Number.isSafeInteger(42)); // true
console.log(Number.isSafeInteger(9007199254740992)); // false

26. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

27. Number.prototype.toPrecision()

toPrecision()方法用于將數字轉換為字符串,并保留指定的有效數字位數。

let num = 42.567;
console.log(num.toPrecision(4)); // "42.57"

28. Number.prototype.toString()

toString()方法用于將數字轉換為字符串??梢灾付ɑ鶖担?到36之間的整數),表示將數字轉換為指定進制的字符串。

let num = 42;
console.log(num.toString(2)); // "101010"
console.log(num.toString(16)); // "2a"

29. Number.prototype.valueOf()

valueOf()方法返回Number對象的原始值。

let num = new Number(42);
console.log(num.valueOf()); // 42

30. Number.prototype.toExponential()

toExponential()方法用于將數字轉換為指數形式的字符串。

let num = 42.567;
console.log(num.toExponential(2)); // "4.26e+1"

31. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

32. Number.prototype.isInteger()

Number.isInteger()方法用于判斷一個值是否為整數。

console.log(Number.isInteger(42)); // true
console.log(Number.isInteger(42.5)); // false

33. Number.prototype.isSafeInteger()

Number.isSafeInteger()方法用于判斷一個值是否為安全整數。安全整數是指能夠精確表示為IEEE-754雙精度浮點數的整數。

console.log(Number.isSafeInteger(42)); // true
console.log(Number.isSafeInteger(9007199254740992)); // false

34. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

35. Number.prototype.toPrecision()

toPrecision()方法用于將數字轉換為字符串,并保留指定的有效數字位數。

let num = 42.567;
console.log(num.toPrecision(4)); // "42.57"

36. Number.prototype.toString()

toString()方法用于將數字轉換為字符串??梢灾付ɑ鶖担?到36之間的整數),表示將數字轉換為指定進制的字符串。

let num = 42;
console.log(num.toString(2)); // "101010"
console.log(num.toString(16)); // "2a"

37. Number.prototype.valueOf()

valueOf()方法返回Number對象的原始值。

let num = new Number(42);
console.log(num.valueOf()); // 42

38. Number.prototype.toExponential()

toExponential()方法用于將數字轉換為指數形式的字符串。

let num = 42.567;
console.log(num.toExponential(2)); // "4.26e+1"

39. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

40. Number.prototype.isInteger()

Number.isInteger()方法用于判斷一個值是否為整數。

console.log(Number.isInteger(42)); // true
console.log(Number.isInteger(42.5)); // false

41. Number.prototype.isSafeInteger()

Number.isSafeInteger()方法用于判斷一個值是否為安全整數。安全整數是指能夠精確表示為IEEE-754雙精度浮點數的整數。

console.log(Number.isSafeInteger(42)); // true
console.log(Number.isSafeInteger(9007199254740992)); // false

42. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

43. Number.prototype.toPrecision()

toPrecision()方法用于將數字轉換為字符串,并保留指定的有效數字位數。

let num = 42.567;
console.log(num.toPrecision(4)); // "42.57"

44. Number.prototype.toString()

toString()方法用于將數字轉換為字符串??梢灾付ɑ鶖担?到36之間的整數),表示將數字轉換為指定進制的字符串。

let num = 42;
console.log(num.toString(2)); // "101010"
console.log(num.toString(16)); // "2a"

45. Number.prototype.valueOf()

valueOf()方法返回Number對象的原始值。

let num = new Number(42);
console.log(num.valueOf()); // 42

46. Number.prototype.toExponential()

toExponential()方法用于將數字轉換為指數形式的字符串。

let num = 42.567;
console.log(num.toExponential(2)); // "4.26e+1"

47. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

48. Number.prototype.isInteger()

Number.isInteger()方法用于判斷一個值是否為整數。

console.log(Number.isInteger(42)); // true
console.log(Number.isInteger(42.5)); // false

49. Number.prototype.isSafeInteger()

Number.isSafeInteger()方法用于判斷一個值是否為安全整數。安全整數是指能夠精確表示為IEEE-754雙精度浮點數的整數。

console.log(Number.isSafeInteger(42)); // true
console.log(Number.isSafeInteger(9007199254740992)); // false

50. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

51. Number.prototype.toPrecision()

toPrecision()方法用于將數字轉換為字符串,并保留指定的有效數字位數。

let num = 42.567;
console.log(num.toPrecision(4)); // "42.57"

52. Number.prototype.toString()

toString()方法用于將數字轉換為字符串??梢灾付ɑ鶖担?到36之間的整數),表示將數字轉換為指定進制的字符串。

let num = 42;
console.log(num.toString(2)); // "101010"
console.log(num.toString(16)); // "2a"

53. Number.prototype.valueOf()

valueOf()方法返回Number對象的原始值。

let num = new Number(42);
console.log(num.valueOf()); // 42

54. Number.prototype.toExponential()

toExponential()方法用于將數字轉換為指數形式的字符串。

let num = 42.567;
console.log(num.toExponential(2)); // "4.26e+1"

55. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

56. Number.prototype.isInteger()

Number.isInteger()方法用于判斷一個值是否為整數。

console.log(Number.isInteger(42)); // true
console.log(Number.isInteger(42.5)); // false

57. Number.prototype.isSafeInteger()

Number.isSafeInteger()方法用于判斷一個值是否為安全整數。安全整數是指能夠精確表示為IEEE-754雙精度浮點數的整數。

console.log(Number.isSafeInteger(42)); // true
console.log(Number.isSafeInteger(9007199254740992)); // false

58. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

59. Number.prototype.toPrecision()

toPrecision()方法用于將數字轉換為字符串,并保留指定的有效數字位數。

let num = 42.567;
console.log(num.toPrecision(4)); // "42.57"

60. Number.prototype.toString()

toString()方法用于將數字轉換為字符串??梢灾付ɑ鶖担?到36之間的整數),表示將數字轉換為指定進制的字符串。

let num = 42;
console.log(num.toString(2)); // "101010"
console.log(num.toString(16)); // "2a"

61. Number.prototype.valueOf()

valueOf()方法返回Number對象的原始值。

let num = new Number(42);
console.log(num.valueOf()); // 42

62. Number.prototype.toExponential()

toExponential()方法用于將數字轉換為指數形式的字符串。

let num = 42.567;
console.log(num.toExponential(2)); // "4.26e+1"

63. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

64. Number.prototype.isInteger()

Number.isInteger()方法用于判斷一個值是否為整數。

console.log(Number.isInteger(42)); // true
console.log(Number.isInteger(42.5)); // false

65. Number.prototype.isSafeInteger()

Number.isSafeInteger()方法用于判斷一個值是否為安全整數。安全整數是指能夠精確表示為IEEE-754雙精度浮點數的整數。

console.log(Number.isSafeInteger(42)); // true
console.log(Number.isSafeInteger(9007199254740992)); // false

66. Number.prototype.toLocaleString()

toLocaleString()方法用于將數字轉換為本地化的字符串表示形式。

let num = 1234567.89;
console.log(num.toLocaleString('en-US')); // "1,234,567.89"

67. Number.prototype.toPrecision()

toPrecision()方法用于將數字轉換為字符串,并保留指定的有效數字位數。

let num = 42.567;
console.log(num.toPrecision(4)); // "42.57"

68. Number.prototype.toString

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女