Skip to content

Commit d769970

Browse files
增加Number对象的整理
1 parent a93ec77 commit d769970

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

2 常用操作/01-Number.html

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head lang="en">
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script>
9+
// Number 对象
10+
/**
11+
* 创建
12+
*/
13+
var myNum1 = new Number(77);
14+
var myNum2 = Number(77);
15+
16+
/**
17+
* 获取值
18+
*/
19+
// 获取 Number 原始值,使用 valueOf() 方法
20+
var iNumber1 = myNum1.valueOf();
21+
var iNumber2 = myNum2.toString();
22+
console.log(iNumber1);//77
23+
console.log(iNumber2);//77
24+
25+
/**
26+
* 属性
27+
*/
28+
// constructor 返回对创建此对象的 Number 函数的引用
29+
// MAX_VALUE 可表示的最大的数
30+
// MIN_VALUE 可表示的最小的数
31+
// NaN 非数字值
32+
// NEGATIVE_INFINITY 负无穷大,溢出时返回该值
33+
// POSITIVE_INFINITY 正无穷大,溢出时返回该值
34+
// prototype 使您有能力向对象添加属性和方法
35+
36+
// MAX_VALUE、MIN_VALUE、NEGATIVE_INFINITY、POSITIVE_INFINITY、NaN 是 Number构造函数的属性,而非Number对象的属性
37+
console.log(myNum1.MAX_VALUE);//undefined
38+
console.log(iNumber1.MAX_VALUE);//undefined
39+
console.log(Number.MAX_VALUE);//1.7976931348623157e+308
40+
console.log(Number.MIN_VALUE);//5e-324
41+
console.log(Number.NEGATIVE_INFINITY);//-Infinity
42+
console.log(Number.POSITIVE_INFINITY);//Infinity
43+
console.log(Number.NaN);//NaN
44+
console.log(Number.constructor);//function Function() { [native code] }
45+
console.log(Number.prototype);//Number {[[PrimitiveValue]]: 0}
46+
47+
/**
48+
* 方法
49+
*/
50+
// toString 把数字转换为字符串,使用指定的基数
51+
// toLocaleString 把数字转换为字符串,使用本地数字格式顺序
52+
// toFixed 把数字转换为字符串,结果的小数点后有指定位数的数字
53+
// toExponential 把对象的值转换为指数计数法
54+
// toPrecision 把数字格式化为指定的长度
55+
// valueOf 返回一个 Number 对象的基本数字值
56+
console.log(myNum1.toFixed(2));//77.00
57+
console.log(myNum1.toFixed(2));//77.00
58+
console.log(myNum1.toExponential(2));//7.70e+1 参数代表小数位数
59+
console.log(Number(7777).toPrecision(2));//7.8e+3 出现四舍五入
60+
console.log(Number(7777).toPrecision(5));//7777.0
61+
62+
</script>
63+
</body>
64+
</html>

0 commit comments

Comments
 (0)