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

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
Copyright Pondake ©


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

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


  <div class="getal">1012312312300000</div>
Thomas stinkt mynamjeeff
  <script src=''></script>


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



/*Downloaded from */
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));