NumberLocalizationUtils
NumberLocalizationUtils script from Roblox's player scripts in handling the leaderboard.
Example locale-sensitive number formatting: https://docs.oracle.com/cd/E19455-01/806-0169/overview-9/index.html
Locale specification: [DECIMAL_SEPARATOR] = string for decimal point, if needed [GROUP_DELIMITER] = string for groupings of numbers left of the decimal List section = abbreviations for language, in increasing order
Missing features in this code:
- No support for differences in number of digits per GROUP_DELIMITER. Some Chinese dialects group by 10000 instead of 1000.
- No support for variable differences in number of digits per GROUP_DELIMITER. Indian natural language groups the first 3 to left of decimal, then every 2 after that.
See https://en.wikipedia.org/wiki/Decimal_separator#Digit_grouping
Functions
abbreviate
NumberLocalizationUtils.
abbreviate
(
number:
number
,
locale:
string
,
roundingBehaviourType:
RoundingBehaviourType?
,
numSignificantDigits:
number?
) →
(
)
Abbreviates the number to a truncated amount in a localized way.
print(NumberLocalizationUtils.abbreviate(2500, "en-us", RoundingBehaviourTypes.ROUND_TO_CLOSEST, 3)) --> 2.5k