Created
August 24, 2023 09:48
-
-
Save darraghoriordan/db9b34a0a94126adc9edabfc2dd37df9 to your computer and use it in GitHub Desktop.
social number formatter
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
function numberToSocial(bigNum, startAt = 10_000) { | |
return bigNum < startAt ? bigNum : Intl.NumberFormat("en", { | |
notation: "compact", | |
style: "decimal", | |
maximumFractionDigits: 1, | |
roundingMode: "floor", | |
unitDisplay: "narrow", | |
}).format(bigNum) | |
} | |
console.log(numberToSocial(123)); | |
console.log(numberToSocial(1457)); | |
console.log(numberToSocial(10001)); | |
console.log(numberToSocial(10512)); | |
console.log(numberToSocial(2_300_213)); | |
console.log(numberToSocial(1457, 1000)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment