Skip to content

Instantly share code, notes, and snippets.

@RiodeJaneiroo
Last active March 15, 2023 17:30
Show Gist options
  • Save RiodeJaneiroo/a92d13cf38d30c22e7602e2625f939ba to your computer and use it in GitHub Desktop.
Save RiodeJaneiroo/a92d13cf38d30c22e7602e2625f939ba to your computer and use it in GitHub Desktop.
[Разбить число на разряды JS] #js #javascript #number
// Method #1
var num = 1234567890;
var result = num.toLocaleString(); // or .toLocaleString('ru');
console.log(result);
// Method #2
function numberWithSpaces(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
}
console.log(numberWithSpaces(100));
console.log(numberWithSpaces(10000));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment