亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript Number 物件

介紹

Number 對(duì)象,是數(shù)字對(duì)象,包含js中的整數(shù)、浮點(diǎn)數(shù)等等。

定義

#var?a = 1;

var?b = 1.1;

屬性

1?Number.MAX_VALUE :表示JS中最大的數(shù)字,約1.79e+308

2?Number.MIN_VALUE :表示JS中最小的數(shù)字,約5e-324

3?Number.NaN :傳回NaN,表示非數(shù)字值,與任意其他數(shù)字不等,也包括NaN本身。應(yīng)使用Number.isNaN() 來進(jìn)行判斷。

4?Number.NEGATIVE_INFINITY?:回傳 -Infinity ,表示負(fù)無窮。

5?Number.POSITIVE_INFINITY ?:回到?Infinity ,表示正無限。進(jìn)行計(jì)算的值大於Number.MAX_VALUE就回傳?Infinity 。

方法

#1 Number.isInteger(value) :判斷參數(shù)是否為整數(shù)

#參數(shù):

①value?{Number} :數(shù)字

傳回值:

{Boolean} 傳回參數(shù)是否為整數(shù)?。純整數(shù)的字串也回傳false。

範(fàn)例:

Number.isInteger(1);?// => true

Number.isInteger(1.1);?// => false

#Number.isInteger('1');?// => false :純整數(shù)的字串也回傳false

Number.isInteger('1.1');?// => false

Number.isInteger('a');?// => false :非字串回傳false

2?Number.isNaN(value) :判斷參數(shù)是否為NaN

#參數(shù):

①value?{Object} :任意型別

傳回值:

{Boolean} 傳回參數(shù)是否為NaN 。

範(fàn)例:

Number.isNaN(NaN);?// => true

Number.isNaN('NaN');?// => false :' NaN'字串,並非為NaN

Number.isNaN(1);?// => false

Number.isNaN('1');?// => false

3?Number.parseFloat(value) :將參數(shù)轉(zhuǎn)換成浮點(diǎn)數(shù)

參數(shù):

①value?{Number | NumberStr} :數(shù)字或純數(shù)字的字串

傳回值:

{Integer?| Float} 傳回整數(shù)或浮點(diǎn)數(shù)數(shù)值

範(fàn)例:

Number.parseFloat(1);?// => 1 :整數(shù)或傳回整數(shù)

Number.parseFloat(1.1);?// => 1.1

Number.parseFloat('1aaa');?// => 1 :字串前面為數(shù)字的,只回傳數(shù)字

#Number.parseFloat('1.1aaa');?// => 1.1

Number.parseFloat('a1');?// => NaN :非數(shù)字開頭,回傳NaN

#Number.parseFloat('a');?// => NaN

4?Number.parseInt(value) :將參數(shù)轉(zhuǎn)換為整數(shù)

#參數(shù):

#①value?{Number | NumberStr} :數(shù)字或純數(shù)字的字串

傳回值:

{Integer} 傳回整數(shù)數(shù)值

範(fàn)例:

Number.parseInt(1);?// => 1

Number.parseInt(1.1);?// => 1 :浮點(diǎn)數(shù)回傳整數(shù)

Number.parseInt('1aaa' );?// => 1 :字串前面為數(shù)字的,只回傳數(shù)字

Number.parseInt('1.1aaa');?// => 1

Number.parseInt ('a1');?// => NaN :非數(shù)字開頭,回傳NaN

Number.parseInt('a');?// => NaN


######### #####八進(jìn)位和十六進(jìn)位######如果前綴為0,則JavaScript 會(huì)把數(shù)值常數(shù)解釋為八進(jìn)位數(shù),如果前綴為0 和"x",則解釋為十六進(jìn)位數(shù)。 ###
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)(php.cn)</title>
</head>
<body>
<script>
var y = 0377;
var z = 0xFF; 
document.write(y + "<br>");
document.write(z + "<br>");
</script>
</body>
</html>
###預(yù)設(shè)情況下,JavaScript 數(shù)字為十進(jìn)位顯示。 ######但你可以使用 toString() 方法 輸出16進(jìn)位、8進(jìn)位、2進(jìn)位。 ###
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)(php.cn)</title>
</head>
<body>
<script>
var myNumber = 28;
document.write(myNumber + ' 十進(jìn)制<br>');
document.write(myNumber.toString(16) + ' 十六進(jìn)制<br>');
document.write(myNumber.toString(8) + ' 八進(jìn)制<br>');
document.write(myNumber.toString(2) + ' 二進(jìn)制<br>');
</script>
</body>
</html>
###無窮大(Infinity)######當(dāng)數(shù)字運(yùn)算結(jié)果超過了JavaScript所能表示的數(shù)字上限(溢出),結(jié)果為一個(gè)特殊的無窮大(infinity)值,在JavaScript中以Infinity表示。同樣地,當(dāng)負(fù)數(shù)的值超過了JavaScript所能表示的負(fù)數(shù)範(fàn)圍,結(jié)果為負(fù)無窮大,在JavaScript中以-Infinity表示。無窮大值的行為特性和我們所期望的是一致的:基於它們的加、減、乘和除運(yùn)算結(jié)果還是無限大(當(dāng)然還保留它們的正負(fù)號(hào))。 ###
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)(php.cn)</title>
</head>
<body>
<script>
myNumber=2;
while (myNumber!=Infinity){
myNumber=myNumber*myNumber;
document.write(myNumber +'<BR>');
}
</script>
</body>
</html>
###數(shù)字屬性######MAX_VALUE######MIN_VALUE###

NEGATIVE_INFINITY

POSITIVE_INFINITY

NaN

原型

建構(gòu)子

數(shù)位方法

toExponential()

toFixed()

toPrecision()

toString()

valueOf()


#
繼續(xù)學(xué)習(xí)
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script type="text/javascript"> var test1= new Boolean(true); var test2= new Boolean(false); var test3= new Date(); var test4= new String("999"); var test5= new String("999 888"); var test6= new String("www.itxueyuan.com"); document.write(Number(test1)+ "<br>"); document.write(Number(test2)+ "<br>"); document.write(Number(test3)+ "<br>"); document.write(Number(test4)+ "<br>"); document.write(Number(test5)+ "<br>"); document.write(Number(test6)+ "<br>"); </script> </head> <body> </body> </html>
提交重置程式碼