parseFloat在js里面怎么用??
<script type="text/javascript">
function change() {
var a = document.getElementById("a").value
var b = document.getElementById("b").value;
var c = document.getElementById("c").value;
var d = document.getElementById("d").value
var e = document.getElementById("e");
if (a == "" || b == "" || c == "" || d == "") return;
e.value = parseFloat (a) + parseFloat (b) + parseFloat (c) + parseFloat (d);
}
</script>
<input id=a type=text><br>
<input id=b type=text><br>
<input id=c type=text><br>
<input id=d type=text><br>
<input id=e type=text>
其中e是a+b+c+d的结果,但是用了parseFloat来计算总价之后,结果有时候会是1224.000000000009 这样的,可以精确到小数点后2位吗?比如1224.00?
------解决方案--------------------大写parseFloat (a).toFixed(2)