Home >Web Front-end >JS Tutorial >How to implement regular expression judgment to retain 2 decimal places
这次给大家带来正则表达式怎样实现保留2位小数的判定,正则表达式实现保留2位小数判定的注意事项有哪些,下面就是实战案例,一起来看一下。
废话不多说了,直接给大家贴代码了,具体代码如下所示:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/jquery.min.js" ></script> </head> <body> <li><a class="ba">6.88888888</a></li> <script> var b=$('.ba').html(); onload = function(){ var a = b; var aNew; var re = /([0-9]+\.[0-9]{2})[0-9]*/; aNew = a.replace(re,"$1"); $(".ba").html(aNew) } </script> </body> </html>
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
The above is the detailed content of How to implement regular expression judgment to retain 2 decimal places. For more information, please follow other related articles on the PHP Chinese website!