So I have a leaderstats put in called CC (Cactus Coins, don't judge it.) and I want to make it so that if it's 1,000,000 it'll change to 1M instead of 1,000,000. And if it's a billion, make it 1B, and if it's 140 million, make it 140M rather than all the digits. How would I do that without calling hundreds of lines of code?
local letters = { "K", "M", "B", "T", "QD", "QN", "SX", "SP", "O", "NO", "DEC", "UND", "DUOD", "TRED", "QUATD", "QND", "SXD", "SPD", "OD", "NOVD", -- I really doubt somebody will get more than a novemdecillion --put more here } local nums = {} for q=1,#letters do local dig = (q*3)+1 --digits local letter = 1*(10^(dig-1)) --for dividing purposes table.insert(nums,#nums+1,letter) --insert end function shorten(num) local len = math.ceil(math.log10(num + .5)) --get the digits if len>=4 then --check if it's ok to shorten for q=1,#letters do local dig = (q*3)+1 --smallest number of digits the letter is if len <= dig+2 then --check if this digit works local toDo = math.floor(num/nums[q]) --the dividing number local newNum = toDo..letters[q] --the new num return newNum --return it end end end end print(shorten(1789000000000000000))--it returns the shortened num
Then do what firedDusk said, use a StringValue when displaying the numbers
Well when changing to 1,000,000 that uses a Number Value or Int Value. But if you are wanting to change it to 1M or 1B then you use a string value.