<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www./1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>整數(shù)與浮點(diǎn)數(shù)的轉(zhuǎn)換</title> </head>
<body> <script language="javascript" type="text/javascript"> document.write("整數(shù)轉(zhuǎn)換函數(shù):parseInt(數(shù)據(jù),底數(shù))<br>"); document.write("10101=>" + parseInt("10101",2)+"<br>"); document.write("77=>" + parseInt("77",8)+"<br>"); document.write("2A3B=>" + parseInt("2A3B",16)+"<br>"); document.write("077=>" + parseInt("077")+"<br>"); document.write("0X2A3B=>" + parseInt("0X2A3B")+"<br>"); document.write("浮點(diǎn)數(shù)轉(zhuǎn)換函數(shù):parseFloat(數(shù)據(jù))<br>"); var str = "12.345"; var str1 = str + 6; var str2 = parseFloat(str) + 6; document.write(str1 + "=>" + parseFloat(str1)+"<br>"); document.write(str1 + "=>" + parseFloat(str2)+"<br>"); document.write("34.89a23=>" + parseFloat("34.89a23")+"<br>"); document.write("數(shù)字判斷函數(shù):isNaN<br>"); document.write("4是數(shù)字:"+!isNaN(4)+"<br>"); document.write("ffff是數(shù)字:"+!isNaN("ffff")+"<br>"); </script> </body> </html>
輸出:
整數(shù)轉(zhuǎn)換函數(shù):parseInt(數(shù)據(jù),底數(shù)) 10101=>21 77=>63 2A3B=>10811 077=>63 0X2A3B=>10811 浮點(diǎn)數(shù)轉(zhuǎn)換函數(shù):parseFloat(數(shù)據(jù)) 12.3456=>12.3456 12.3456=>18.345 34.89a23=>34.89 數(shù)字判斷函數(shù):isNaN 4是數(shù)字:true ffff是數(shù)字:false
|