Iam not to good with mathematics but I get around coding fine, lately I started to get onto Lua I used to program as a hobby on Pascal, Basic and VB 6.
I have a probleam I wanted to transform a long number like 1500000 into 1.5 Mil or 500000 into 500k, wanted to use this for a little addon I been developing and this would make easy to read large numbers
I know some of you already wrote code for this I saw this into Skada, Recount, Shadowed Unit Frames. I had dug into said addons to take some ideas but complexity of those addons are to big for me atm
I was hoping if someone could help me with a code snippet or the algoritm in english.
If you looked at those addons, why did you not just copy it from there?
Nevertheless, here's a fish:
local function ReadableNumber(num, places)
local placeValue = ("%%.%df"):format(places or 0)
if not num then
elseif num >= 1000000000000 then
ret = placeValue:format(num / 1000000000000) .. " Tril" -- trillion
elseif num >= 1000000000 then
ret = placeValue:format(num / 1000000000) .. " Bil" -- billion
elseif num >= 1000000 then
ret = placeValue:format(num / 1000000) .. " Mil" -- million
elseif num >= 1000 then
ret = placeValue:format(num / 1000) .. "k" -- thousand
ret = num -- hundreds
Blizzard has a built in function you might like to use. it's used for unit frames,
actualy it doesnt work very good for large numbers example it turns 1 000 000 into 1000 k instead of 1 mil
egingell thanks for that code I had looked into those addons code but the code is way to complex for my programming experience so I got lost into it adding the fact that iam new at Lua sintax, but it seems thats exacly what I may need I gona work on it thanks
edit: egingell thanks alot for that fish ;) thats exacly what I needed working like a charm