I made a script function that will abbreviate any number inserted into it with the proper notation selected for it (scientific as 1 or letters as 2, letters is default):
function Abbreviate(numberHere,Notation) -- Notation: 1 = Scientific, 2 = Letters, Default = 2
local DigitsInNumber = math.max(math.ceil(math.log10(numberHere+1)),1)
local FormattedNumber
local NotationToUse
if Notation == 1 then -- Scientific Notation
FormattedNumber = string.sub(tostring(numberHere/10^(DigitsInNumber-1)),1,3)
NotationToUse = FormattedNumber.."e"..DigitsInNumber-1
elseif (Notation and Notation == 2) or not Notation then -- Letters
local TableOfLetters = {
"",
"K",
"M",
"B",
"T",
"Qa",
"Qi",
"Sx",
"Sp",
"Oc",
"No",
"Dc",
"Ud",
"Dd"
}
local NumberOfDigitsToShow = 1.5*(DigitsInNumber%3)^2 - 3.5*(DigitsInNumber%3) + 5 -- (0,5), (1,3), (2,4)
FormattedNumber = string.sub(tostring(numberHere/10^(DigitsInNumber-1)),1,NumberOfDigitsToShow)
local FinalNumber = string.sub(FormattedNumber*(10^((DigitsInNumber-1)%3)),1,NumberOfDigitsToShow)
if DigitsInNumber == 3 then
FinalNumber = tostring(math.ceil(tonumber(FinalNumber))) -- For floating point errors
end
NotationToUse = FinalNumber..TableOfLetters[math.ceil(DigitsInNumber/3)]
end
return NotationToUse
end
print(Abbreviate(2530)) -- Example of usage for letter format
print(Abbreviate(2530,1)) -- Example of usage for scientific notation
I have already made quite a lot of improvements to it and made it more accurate as well. The way that I want to improve it is by making it possibly faster to run (all the math will probably make it run slower I assume?) Is there a way to remove any of the math but still get the same numbers needed? Scientific works well, specifically talking about getting less math for the letter notation if possible