Skip to content

Instantly share code, notes, and snippets.

@ChanManChan
Created February 27, 2020 16:38
Show Gist options
  • Select an option

  • Save ChanManChan/53e02f42d89b9a2cf6b6803fde1c2316 to your computer and use it in GitHub Desktop.

Select an option

Save ChanManChan/53e02f42d89b9a2cf6b6803fde1c2316 to your computer and use it in GitHub Desktop.
var x=12345652457.557;
  x=x.toString();
  var afterPoint = '';
  if(x.indexOf('.') > 0)
     afterPoint = x.substring(x.indexOf('.'),x.length);
  x = Math.floor(x);
  x=x.toString();
  var lastThree = x.substring(x.length-3);
  var otherNumbers = x.substring(0,x.length-3);
  if(otherNumbers != '')
      lastThree = ',' + lastThree;
  var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree + afterPoint;
  
  alert(res);
  ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment