本文實(shí)例講述了JS實(shí)現(xiàn)的數(shù)字格式化功能.分享給大家供大家參考,具體如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>數(shù)字格式化</title><script type="text/javascript" language="javascript" >//n為要轉(zhuǎn)化的數(shù)字/數(shù)字字符串,s為后面要加的單位,可為空function num2money(n, s){ if (typeof s == "undefined") s = ""; n = parseInt(n); n = parseInt(n) + Number(((n - parseInt(n)) + "").substring(0, 3)); if (n / 1000 >= 1) { var nn = '' + n; nn = nn.substring(nn.length - 3, nn.length); s = ',' + nn + s; return num2money(parseInt(n / 1000), s); } else { return n + s; }}document.write(num2money("123.45", "美元"));//輸出:123美元</script></head><body></body></html>
PS:這里再為大家推薦幾款計(jì)算工具供大家進(jìn)一步參考借鑒:
在線一元函數(shù)(方程)求解計(jì)算工具:
http://tools.VeVB.COm/jisuanqi/equ_jisuanqi
科學(xué)計(jì)算器在線使用_高級(jí)計(jì)算器在線計(jì)算:
http://tools.VeVB.COm/jisuanqi/jsqkexue
在線計(jì)算器_標(biāo)準(zhǔn)計(jì)算器:
http://tools.VeVB.COm/jisuanqi/jsq
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript數(shù)組操作技巧總結(jié)》、《JavaScript排序算法總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》及《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注