Skip to main content

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(
numbernumber,
localestring,
roundingBehaviourTypeRoundingBehaviourType?,
numSignificantDigitsnumber?
) → ()

Abbreviates the number to a truncated amount in a localized way.

print(NumberLocalizationUtils.abbreviate(2500, "en-us", RoundingBehaviourTypes.ROUND_TO_CLOSEST, 3)) --> 2.5k
Show raw api
{
    "functions": [
        {
            "name": "abbreviate",
            "desc": "Abbreviates the number to a truncated amount in a localized way.\n\n```lua\nprint(NumberLocalizationUtils.abbreviate(2500, \"en-us\", RoundingBehaviourTypes.ROUND_TO_CLOSEST, 3)) --> 2.5k\n```",
            "params": [
                {
                    "name": "number",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "roundingBehaviourType",
                    "desc": "",
                    "lua_type": "RoundingBehaviourType?"
                },
                {
                    "name": "numSignificantDigits",
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 276,
                "path": "src/clienttranslator/src/Client/NumberLocalizationUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "NumberLocalizationUtils",
    "desc": "NumberLocalizationUtils script from Roblox's player scripts in handling the leaderboard.\n\nExample locale-sensitive number formatting:\nhttps://docs.oracle.com/cd/E19455-01/806-0169/overview-9/index.html\n\nLocale specification:\n[DECIMAL_SEPARATOR] = string for decimal point, if needed\n[GROUP_DELIMITER] = string for groupings of numbers left of the decimal\nList section = abbreviations for language, in increasing order\n\nMissing features in this code:\n- No support for differences in number of digits per GROUP_DELIMITER.\nSome Chinese dialects group by 10000 instead of 1000.\n- No support for variable differences in number of digits per GROUP_DELIMITER.\nIndian natural language groups the first 3 to left of decimal, then every 2 after that.\n\nSee https://en.wikipedia.org/wiki/Decimal_separator#Digit_grouping",
    "source": {
        "line": 23,
        "path": "src/clienttranslator/src/Client/NumberLocalizationUtils.lua"
    }
}