Comma na 2 getallen

In this example below you will see how to do a Comma na 2 getallen with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by Pondake, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright Pondake ©

Technologies

  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Comma na 2 getallen</title>
  
  
  
  
  
</head>

<body>

  <div class="getal">1012312312300000</div>
Thomas stinkt mynamjeeff
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/Pondake/comma-na-2-getallen-GObKLm */
function removeAllButLast(string, token) {
    /* Requires STRING not contain TOKEN */
    var parts = string.split(token);
    return parts.slice(0,-1).join('') + token + parts.slice(-1)
}

function commaSeparateNumber(val){
    while (/(\d+)(\d{3})/.test(val.toString())){
      val = val.toString().replace(/(\d+)(\d{2})/, '$1'+','+'$2');
      val = removeAllButLast(val, ',');
      val = val.toString().replace(/(\d+)(\d{3})/, '$1'+'.'+'$2');
    }
    return val;
  }
$getal = $('.getal').text();
$getal = (commaSeparateNumber($getal));
console.log($getal);

Comments