多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > web前端 > jscript > javascript parseInt&Number函數(shù)的區(qū)別

javascript parseInt&Number函數(shù)的區(qū)別

來源:程序員人生   發(fā)布時(shí)間:2014-06-06 09:02:18 閱讀次數(shù):2654次

在js中,如果你使用parseInt("08"),一般都會(huì)認(rèn)為會(huì)返回8,然而實(shí)際上返回了0.但是用Number("08")返回的才是8.

但是parseInt("08", 10)是可以返回8的。

為搞清楚兩者的區(qū)別,

參考了別人寫的parseInt&Number的區(qū)別:

parseInt
Parses a string argument and returns an integer of the specified radix or base.
核心函數(shù)
實(shí)現(xiàn)版本 Navigator 2.0: If the first character of the string specified in parseInt(string) cannot be converted to a number, returns "NaN" on Solaris and Irix and 0 on all other platforms.Navigator 3.0, LiveWire 2.0: Returns "NaN" on all platforms if the first character of the string specified in parseInt(string) cannot be converted to a number.

語法
parseInt(string,radix)
參數(shù)
string A string that represents the value you want to parse.
radix (Optional) An integer that represents the radix of the return value.

描述
The parseInt function is a built-in JavaScript function.
The parseInt function parses its first argument, a string, and attempts to return an integer of the specified radix (base). For example, a radix of 10 indicates to convert to a decimal number, 8 octal, 16 hexadecimal, and so on. For radixes above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.

If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates numbers to integer values.

If the radix is not specified or is specified as 0, JavaScript assumes the following:

If the input string begins with "0x", the radix is 16 (hexadecimal).

If the input string begins with "0", the radix is eight (octal).

If the input string begins with any other value, the radix is 10 (decimal).
If the first character cannot be converted to a number, parseInt returns "NaN".
For arithmetic purposes, the "NaN" value is not a number in any radix. You can call the isNaN function to determine if the result of parseInt is "NaN". If "NaN" is passed on to arithmetic operations, the operation results will also be "NaN".

示例
The following示例 all return 15:
parseInt("F", 16)
parseInt("17", 8)
parseInt("15", 10)
parseInt(15.99, 10)
parseInt("FXX123", 16)
parseInt("1111", 2)
parseInt("15*3", 10) The following示例 all return "NaN":

parseInt("Hello", 8)
parseInt("0x7", 10)
parseInt("FFF", 10) Even though the radix is specified differently, the following示例 all return 17 because the input string begins with "0x".

parseInt("0x11", 16)
parseInt("0x11", 0)
parseInt("0x11")
-----------------------------------------------
將指定對(duì)象轉(zhuǎn)換為數(shù)字。
核心函數(shù)
實(shí)現(xiàn)版本 Navigator 4.0, Netscape Server 3.0

語法
Number(obj)
參數(shù)
obj 一個(gè)對(duì)象。

描述
如果對(duì)象是 Date 類型的對(duì)象,Number 將返回自格林威治標(biāo)準(zhǔn)時(shí)間 1970 年 1 月 1 日起已經(jīng)經(jīng)過的毫秒數(shù),在此日期之后的是正數(shù),之前的是負(fù)數(shù)。
如果 obj 是一個(gè)沒有數(shù)字格式的字符串,Number 將返回 NaN。

示例  
下面的例子將把   Date   對(duì)象轉(zhuǎn)換為數(shù)值型值:    
  <SCRIPT>  
  d   =   new   Date   ("December   17,   1995   03:24:00");    
  document.write   (Number(d)   +   "<BR>");  

生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 欧美深夜在线 | 国产精品系列在线一区 | 一区二区免费视频 | 亚洲精品第五页 | 久久精品国产亚洲精品 | 一区二区三区四区在线观看视频 | 最近的中文字幕免费视频1 最近的中文字幕免费完整 最近的中文字幕视频大全高清 | 色啪视频 | 毛片观看网址 | 免费播放春色aⅴ视频 | 久久www免费人成看片入口 | 国产精品久久久亚洲 | 亚洲欧美综合另类 | 欧美性淫 | 久久久久久综合 | 川上优最新中文字幕不卡 | 国产免费a v吧在线观看不卡 | 国内精品网站 | 日本xxwwwxxxx网站 | 女bbwxxxx视频 | 成人a网| 亚洲欧美一区二区三区国产精品 | 亚洲国产精品久久精品成人 | 国产成人亚洲精品2020 | 国内精品免费视频精选在线观看 | 亚洲国产高清在线精品一区 | 免费看羞羞| 国产高清毛片 | 亚洲欧美另类视频 | 毛片网站网址 | 午夜在线播放视频在线观看视频 | japanese日本护士xxxx18一19 | 国产乱码一区二区三区四 | 国产五月 | 日韩亚洲国产欧美精品 | www.日本高清 | 国产成人久视频免费 | 欧美日本韩国一区二区 | 国产毛片久久精品 | 欧美在线亚洲国产免m观看 欧美在线一二三 | 欧美综合视频在线 |