Home >Web Front-end >JS Tutorial >How to implement regular expression judgment to retain 2 decimal places

How to implement regular expression judgment to retain 2 decimal places

php中世界最好的语言
php中世界最好的语言Original
2018-03-29 13:53:474233browse

这次给大家带来正则表达式怎样实现保留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中文网其它相关文章!

推荐阅读:

Linux grep与正则表达式的使用

正则表达式匹配URL、电话、手机、邮箱的方法

Replace中的正则表达式使用详解

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!

Statement:
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