js2位小数点价格验证

<!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></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>

你可能感兴趣的:(js)