local S={[2]="\077";[3]="\066";[4]="\084";[5]="\081\100",[6]="\081\116";[7]="\083\120",[8]="\083\112";[9]="\079\116";[10]="\078\110",[11]="\068\101",[12]="\085\100",[13]="\068\100";[14]="\084\100",[15]="\081\100\068",[16]="\081\116\068",[17]="\083\120\068";[18]="\083\112\068";[19]="\079\116\068",[20]="\078\110\068",[21]="\086\105"}local I={en_us=3}local z={en_us=S}return function(S,f,p)f=f or false p=p or"\101\110\095\117\115"assert(typeof(S)=="\110\117\109\098\101\114")local y=I[p]or 3 local V=z[p]if S==math.huge then return"\073\110\102\105\110\105\116\121"end local u=math.floor(math.log10(S))local P=V[math.floor(u/y)]if not P then return tostring(S)end local Y=S/10^(math.floor(u/y)*y)local o=("\037\046"..(y.."\102")):format(Y)if not f then o=string.gsub(o,"\048\043\036","")o=string.gsub(o,"\037\046\043\036","")end return("\037\115\037\115"):format(o,P)end
local magnitudes_en_us = {
    --[1] = "K",
    [2] = "M",
    [3] = "B",
    [4] = "T",
    [5] = "Qd",
    [6] = "Qt",
    [7] = "Sx",
    [8] = "Sp",
    [9] = "Ot",
    [10] = "Nn",
    [11] = "De",
    [12] = "Ud",
    [13] = "Dd",
    [14] = "Td",
    [15] = "QdD",
    [16] = "QtD",
    [17] = "SxD",
    [18] = "SpD",
    [19] = "OtD",
    [20] = "NnD",
    [21] = "Vi",
}

local localeMagnitudeWidths = {
    en_us = 3,
}

local localeSuffixes = {
    en_us = magnitudes_en_us,
}

return function(inNumber, dontTruncate, locale)
    dontTruncate = dontTruncate or false
    locale = locale or "en_us"
    assert(typeof(inNumber) == "number")

    local magnitudeWidth = localeMagnitudeWidths[locale] or 3
    local magnitudes = localeSuffixes[locale]
    if inNumber == math.huge then return "Infinity" end -- auto translate should catch this?

    local magnitude = math.floor(math.log10(inNumber))
    local suffix = magnitudes[math.floor(magnitude/magnitudeWidth)]

    if not suffix then return tostring(inNumber) end

    local fraction = inNumber/(10^(math.floor(magnitude/magnitudeWidth)*magnitudeWidth))
    local formattedNumber = ("%."..magnitudeWidth.."f"):format(fraction)
    if not dontTruncate then
        formattedNumber = string.gsub(formattedNumber, "0+$", "")
        formattedNumber = string.gsub(formattedNumber, "%.+$", "")
    end
    return ("%s%s"):format(formattedNumber,suffix)
end