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;
}
});