Skip to main content

numberFormatUtil

A simple utility for formatting numbers in human readable format.

Functions

numberToTuple

numberFormatUtil.numberToTuple(numbernumber) → string?

Returns the given number's tuple, if any. Supports up to 57 tuples!

print(numberFormatUtil.numberToTuple(2)) --> "Double"
print(numberFormatUtil.numberToTuple(3)) --> "Triple"
print(numberFormatUtil.numberToTuple(4)) --> "Quadruple"

ordinal

numberFormatUtil.ordinal(numbernumber) → string

Returns the given number in ordinal format.

print(numberFormatUtil.ordinal(24)) --> "24th"

spsToMph

numberFormatUtil.spsToMph(spsnumber) → number

Formats sps (studs per second) to mph (miles per second).

print(numberFormatUtil.spsToMph(100, 50, 25)) --> 0.75

suffix

numberFormatUtil.suffix(numbernumber) → string

Return a string as the formatted version of number.

Cannot format extremely large numbers

This method will struggle to format numbers larger than approximately 10^68.

print(numberFormatUtil.suffix(10^70)) --> 10 (no formatting...)
print(numberFormatUtil.suffix(1650)) --> "1.65K"

Additionally, if number is lower than 1, then this method will just return number (stringified).

commas

numberFormatUtil.commas(targetnumber) → string

Returns a number stringified, formatted with commas.

print(numberFormatUtil.commas(15000)) --> 15,000

toHMS

numberFormatUtil.toHMS(secondsnumber) → string

Returns the given seconds formatted in HMS format as a string.

print(numberFormatUtil.toHMS(3600)) --> "01:00:00"

toMS

numberFormatUtil.toMS(secondsnumber) → string

Returns the given seconds formatted in MS format as a string.

print(numberFormatUtil.toHMS(60)) --> "01:00"

toS

numberFormatUtil.toS(secondsnumber) → string

Returns the given seconds formatted in S format as a string.

print(numberFormatUtil.toHMS(60)) --> "1:00"
Show raw api
{
    "functions": [
        {
            "name": "numberToTuple",
            "desc": "Returns the given `number`'s tuple, if any. Supports up to `57` tuples!\n\n```lua\nprint(numberFormatUtil.numberToTuple(2)) --> \"Double\"\nprint(numberFormatUtil.numberToTuple(3)) --> \"Triple\"\nprint(numberFormatUtil.numberToTuple(4)) --> \"Quadruple\"\n```",
            "params": [
                {
                    "name": "number",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string?\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 103,
                "path": "src/numberFormatUtil/init.luau"
            }
        },
        {
            "name": "ordinal",
            "desc": "Returns the given number in ordinal format.\n\n```lua\nprint(numberFormatUtil.ordinal(24)) --> \"24th\"\n```",
            "params": [
                {
                    "name": "number",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 115,
                "path": "src/numberFormatUtil/init.luau"
            }
        },
        {
            "name": "spsToMph",
            "desc": "Formats `sps` (studs per second) to `mph` (miles per second).\n\n```lua\nprint(numberFormatUtil.spsToMph(100, 50, 25)) --> 0.75\n```",
            "params": [
                {
                    "name": "sps",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 139,
                "path": "src/numberFormatUtil/init.luau"
            }
        },
        {
            "name": "suffix",
            "desc": "Return a string as the formatted version of `number`. \n\n:::warning Cannot format extremely large numbers\nThis method will struggle to format numbers larger than approximately `10^68`. \n\n```lua\nprint(numberFormatUtil.suffix(10^70)) --> 10 (no formatting...)\n```\n:::\n\n```lua\nprint(numberFormatUtil.suffix(1650)) --> \"1.65K\"\n```\n\nAdditionally, if `number` is lower than `1`, then this method will just return `number` (stringified).",
            "params": [
                {
                    "name": "number",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 160,
                "path": "src/numberFormatUtil/init.luau"
            }
        },
        {
            "name": "commas",
            "desc": "Returns a number stringified, formatted with commas.\n\n```lua\nprint(numberFormatUtil.commas(15000)) --> 15,000\n```",
            "params": [
                {
                    "name": "target",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 182,
                "path": "src/numberFormatUtil/init.luau"
            }
        },
        {
            "name": "toHMS",
            "desc": "Returns the given `seconds` formatted in `HMS` format as a string.\n\n```lua\nprint(numberFormatUtil.toHMS(3600)) --> \"01:00:00\"\n```",
            "params": [
                {
                    "name": "seconds",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 205,
                "path": "src/numberFormatUtil/init.luau"
            }
        },
        {
            "name": "toMS",
            "desc": "Returns the given `seconds` formatted in `MS` format as a string.\n\n```lua\nprint(numberFormatUtil.toHMS(60)) --> \"01:00\"\n```",
            "params": [
                {
                    "name": "seconds",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 217,
                "path": "src/numberFormatUtil/init.luau"
            }
        },
        {
            "name": "toS",
            "desc": "Returns the given `seconds` formatted in `S` format as a string.\n\n```lua\nprint(numberFormatUtil.toHMS(60)) --> \"1:00\"\n```",
            "params": [
                {
                    "name": "seconds",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 229,
                "path": "src/numberFormatUtil/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "numberFormatUtil",
    "desc": " \n\nA simple utility for formatting numbers in human readable format.",
    "source": {
        "line": 6,
        "path": "src/numberFormatUtil/init.luau"
    }
}