HowToRoblox

AbbreviationHandler

Mar 25th, 2021 (edited)
2,365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. local abbreviations = {
  2.     N = 10^30;
  3.     O = 10^27;
  4.     Sp = 10^24;
  5.     Sx = 10^21;
  6.     Qn = 10^18;
  7.     Qd = 10^15;
  8.     T = 10^12;
  9.     B = 10^9;
  10.     M = 10^6;
  11.     K = 10^3
  12. }
  13.  
  14.  
  15. function abbreviateNums(number)
  16.    
  17.    
  18.     local abbreviatedNum = number
  19.     local abbreviationChosen = 0
  20.    
  21.    
  22.     for abbreviation, num in pairs(abbreviations) do
  23.        
  24.         if number >= num and num > abbreviationChosen then
  25.            
  26.             local shortNum = number / num
  27.             local intNum = math.floor(shortNum)
  28.                
  29.             abbreviatedNum = tostring(intNum) .. abbreviation .. "+"
  30.             abbreviationChosen = num
  31.         end
  32.     end
  33.    
  34.     return abbreviatedNum
  35. end
  36.  
  37.  
  38.  
  39. print(abbreviateNums(10000000)) --> 10M
  40. print(abbreviateNums(10 ^ 30)) --> 1N
  41. print(abbreviateNums(10 ^ 32)) --> 100N
Add Comment
Please, Sign In to add comment