js adds thousandth implementation code of super simple

  • 2021-07-07 06:03:08
  • OfStack

JS adds a thousandth, and the test can be used


<script language="javascript" type="text/javascript">
function comdify(n){
    var re=/\d{1,3}(?=(\d{3})+$)/g;
    var n1=n.replace(/^(\d+)((\.\d+)?)$/,function(s,s1,s2){return s1.replace(re,"$&,")+s2;});
    return n1;
}

</script>
<input type="text" value="1212133345.78" onblur="this.value=comdify(this.value)">

Related articles: