首页 > 代码库 > js 字符串转 数字

js 字符串转 数字

<html><body><script language="javascript">var a = "0.11";var b = "0.2801";var c = "1.002"; var sum1 = parseFloat(a)+parseFloat(b)+parseFloat(c);var sum2 = (parseFloat(a)+parseFloat(b)+parseFloat(c)).toFixed(4)document.write("a+b+c="+sum1);document.write("<br/>")document.write("a+b+c="+sum2)document.write("<br/>")var num=new Number(sum2);document.write("sum2.toFixed(2)= "+num.toFixed(2));</script></body></html>

js 字符串转 数字