js 小数相加
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script> function aa() { var a = Number($("#txt1").val()); var b = Number($("#txt2").val()); var c = Number($("#txt3").val()); alert(Number((a + b).toFixed(2)));//结果:13.4 alert((a + b) == c);//结果:false alert(Number((a + b).toFixed(2)) == Number(c.toFixed(2)));//结果:true } </script> <script src="Js/jquery-1.8.3.min.js"></script> </head> <body> <form id="form1" runat="server"> <div> <input id="txt1" type="text" value="9.2" /> <input id="txt2" type="text" value="4.2" /> <input id="txt3" type="text" value="13.4" /> <input id="Button1" type="button" onclick="aa();" value="button" /> </div> </form> </body> </html>