验证小数点之后两位,并且可以四舍五入,代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>验证价格中的小数点后两位 - www.jb200.com</title> <script type="text/javascript"> //验证小数点之后为两位,且四舍五入。 function Should_Money() { var OUGHT_LM = 11.257; // var Omoney = MathRound(parseFloat(OUGHT_LM)); alert(Omoney) } function MathRound(LSTR_Num) { var LINT_Num; if (LSTR_Num == "") { LINT_Num = 0; } else { LINT_Num = parseFloat(LSTR_Num); LINT_Num = Math.round(LINT_Num * 100) / 100; } return LINT_Num; } </script> </head> <body> <input value="ok" onclick="Should_Money()" type="submit" /> </body> </html>您可能感兴趣的文章: