问题描述
functionmyfun(){varother_amount=document.getElementById("amount").value;if(isNaN(other_amount)||other_amount==""){alert("请输入数字.");document.all.form1.other_amount.focus();return;}varother_amount_verify=(other_amount*100);if(other_amount<0||other_amount>500||other_amount_verify.indexOf(".")!=-1){alert(other_amount+":other_amount="+other_amount_verify);alert("请输入介于0.1到500元之间的数字.");document.all.form1.other_amount.focus();return;}}问:为啥20.4也弹出"请输入介于0.1到500元之间的数字.",30.4、。。都没有!
解决方案
解决方案二:
1varother_amount_verify=Math.round(other_amount*10000)/100;2String(other_amount_verify).indexOf(".")!=-1
解决方案三:
为啥20.4也弹出"请输入介于0.1到500元之间的数字???????
解决方案四:
其它的都OK!!
解决方案五:
javascript浮点数的误差了。如果你需要判断小数点后有多少位,直接判断吧,不要用乘法。
解决方案六:
浮点数运算有精度的问题20.4X100=2039.9999999999997
时间: 2024-11-29 00:23:52