jquery determines the number of decimal points two digits and automatically deletes decimal two digits

Source: Internet
Author: User

  This article mainly introduces jquery to determine the decimal point two digits and automatically delete decimal two digits after the number, the need for friends can refer to the following

jquery to determine the decimal point two digits and automatically delete decimal two digits after the number     Basic is that the input 12.235689741    will be converted to 12.23, will not be rounded     The JavaScript basics should be able to read it.     does not explain     code as follows: $ ("#fileds"). Find ("Input"). blur (function () {  var value=$ (This). Val ();  if (value = NULL | | value = =) {  return false; }  if (!isnan (value)) {  VA R 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 greater than 5 digits");  return false; } }else{  var numindex = parseint (Value.indexof ("."), 10 );  if (Numindex = = 0) {  $ (this). Val ("");  alertmsg ("the number entered is not canonical");  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; } }); &nbsP  

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.