求各结果保留两位小位的问题。在线等!!
各位:
在表单中插入3个文本框,前2个输入小数后,第三个框自动计算相加结果,并将结果保留两位小数。求代码。谢谢!!
------解决方案--------------------
JScript codevar c=123.444c=.toFixed(2)
------解决方案--------------------
var c=parseFloat(a.toFixed(2))+parseFloat(b.toFixed(2));
------解决方案--------------------
HTML codefunction ja(){ var a=document.getElementById("a1").value; var b=document.getElementById("a2").value; var c=parseFloat(a)+parseFloat(b); document.getElementById("a6").value=parseFloat(c).toFixed(2);}
------解决方案--------------------
JScript codefunction ja(){ var a=document.getElementById("a1").value; var b=document.getElementById("a2").value; var c=parseFloat(a)+parseFloat(b); document.getElementById("a6").value=parseFloat(c).toFixed(2);}
查询谷 - www.chaxungu.com
求各结果保留两位小位的有关问题。
编辑:chaxungu时间:2022-10-02 23:23:33分类:web开发