jquery to determine the decimal point two bit and automatically delete decimal two digits after the number _jquery

Source: Internet
Author: User
jquery determines the number of decimal points two digits and automatically deletes decimal two digits

Basically, enter 12.235689741

It's going to be 12.23, not rounded up.

The JavaScript basics should be visible.

Do not explain
Copy Code code as follows:

$ ("#fileds"). Find ("Input"). blur (function () {
var value=$ (this). Val () ;
if (value = NULL | | value = =) {
return false;
}
if (!isnan (value)) {
var userreg=/^[0-9]+ [.] {1} [0-9] {1,2})? $/;
if (userreg.test (value)) {
if parseint (value). toString (). length > 5) {
$ (this). Val ("");
alertmsg ("the integer entered must not be greater than 5 digits");
return false;
}
}else{
var numindex = parseint (Value.indexof ("."), 10);
if (numindex = 0) {
$ (this). Val ("");
Alertmsg ("the number entered is not specification");
return false;
}
var head = value.substring (0,numindex);
var bottom = value.substring (numindex,numindex+3);
var fianlnum = Head+bottom;
$ (this). Val (Fianlnum);

}
}else{
$ (this). Val ("");
Alertmsg ("Please enter a number");
return false;
}
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.