課程
/前端開(kāi)發(fā)
/JavaScript
/JavaScript進(jìn)階篇
代碼語(yǔ)言中?parsefloat去掉直接顯示txt1?跟txt2的值?為什么
2015-07-27
源自:JavaScript進(jìn)階篇 6-11
正在回答
parseFloat() 函數(shù)可解析一個(gè)字符串,并返回一個(gè)浮點(diǎn)數(shù)。
該函數(shù)指定字符串中的首個(gè)字符是否是數(shù)字。如果是,則對(duì)字符串進(jìn)行解析,直到到達(dá)數(shù)字的末端為止,然后以數(shù)字返回該數(shù)字,而不是作為字符串。
在本例中,我們將使用 parseFloat() 來(lái)解析不同的字符串:
<script type="text/javascript">document.write(parseFloat("10")) document.write(parseFloat("10.00")) document.write(parseFloat("10.33")) document.write(parseFloat("34 45 66")) document.write(parseFloat(" 60 ")) document.write(parseFloat("40 years"))document.write(parseFloat("He was 40"))</script>
輸出:
101010.33346040NaN
GoHr 提問(wèn)者
printf(
舉報(bào)
本課程從如何插入JS代碼開(kāi)始,帶您進(jìn)入網(wǎng)頁(yè)動(dòng)態(tài)交互世界
1 回答parseFloat是什么意思
3 回答請(qǐng)問(wèn)validB()什么意思
3 回答請(qǐng)問(wèn)otest 是什么意思
1 回答請(qǐng)問(wèn)這是什么意思?
5 回答請(qǐng)問(wèn)這是什么意思
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2015-07-27
parseFloat() 函數(shù)可解析一個(gè)字符串,并返回一個(gè)浮點(diǎn)數(shù)。
該函數(shù)指定字符串中的首個(gè)字符是否是數(shù)字。如果是,則對(duì)字符串進(jìn)行解析,直到到達(dá)數(shù)字的末端為止,然后以數(shù)字返回該數(shù)字,而不是作為字符串。
在本例中,我們將使用 parseFloat() 來(lái)解析不同的字符串:
<script type="text/javascript">
document.write(parseFloat("10"))
document.write(parseFloat("10.00"))
document.write(parseFloat("10.33"))
document.write(parseFloat("34 45 66"))
document.write(parseFloat(" 60 "))
document.write(parseFloat("40 years"))
document.write(parseFloat("He was 40"))
</script>
輸出:
10
10
10.33
34
60
40
NaN
2017-07-13