Last active
March 15, 2023 17:30
-
-
Save RiodeJaneiroo/a92d13cf38d30c22e7602e2625f939ba to your computer and use it in GitHub Desktop.
[Разбить число на разряды JS] #js #javascript #number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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