Home > Web Front-end > JS Tutorial > body text

jquery determines two decimal places and automatically deletes the numbers after two decimal places_jquery

WBOY
Release: 2016-05-16 16:55:09
Original
1341 people have browsed it

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

Basically, if you enter 12.235689741

it will be converted to 12.23 without rounding

knows the basics of javascript You should be able to understand it

No explanation

Copy the code 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 entered integer must not be larger than 5 digits");
return false;
}
}else{
var numindex = parseInt (value.indexOf("."),10);
if(numindex == 0){
$(this).val("");
alertMsg("The entered number is not standardized" );
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 Number");
return false;
}
});
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template