Jquery determines the number after two decimal places and automatically deletes the decimal places _ jquery

Source: Internet
Author: User
This article mainly introduces jquery's number after determining two decimal places and automatically deleting two decimal places. If you need a friend, you can refer to jquery's number after determining two decimal places and automatically deleting two decimal places.

Basically, enter 12.235689741

It will be converted to 12.23, not rounded up.

I should be able to understand the basics of javascript.

Not explained

The Code is 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 input integer cannot be greater than 5 digits ");
Return false;
}
} Else {
Var numindex = parseInt (value. indexOf ("."), 10 );
If (numindex = 0 ){
$ (This). val ("");
AlertMsg ("invalid number entered ");
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 ("enter a number ");
Return false;
}
});

Related Article

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.