View Single Post
09-25-17, 06:34 PM   #13
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,878
Originally Posted by Uitat View Post
is more then 1,000,000
please for the love of god add a period and 2 digits behind.
i.e. 1.05 mil , 1.15 bil, 4.05 bil, 900 mil, 45 bil and so on
I'm not sure if the means everything over a mil. has 2 places (which is what I took it as.)

If the desire is that anything with exact multiples of a mil., bil, tril. will show no places then you would need to add a mod() operation to see if there is any remainder and format accordingly.

The general idea (could be cleaner):
Code:
    local function ReadableNumber(num)
        local ret
        local placeValue = ("%%.%df"):format(2) --probably can be improved into "%.0f"
        if not num then
            return "0 "
        elseif num >= 1000000000000 then
            if mod(num, 1000000000000) == 0 then
            	ret = num / 1000000000000 .. " Tril"
            else
            	ret = placeValue:format(num / 1000000000000) .. " Tril" -- trillion
            end
        elseif num >= 1000000000 then
            if mod(num, 1000000000) == 0 then
            	ret = num / 1000000000 .. " Bil"
            else
            	ret = placeValue:format(num / 1000000000)  .. " Bil" -- billion
            end
        elseif num >= 1000000 then
            if mod(num, 1000000) == 0 then
            	ret = num / 1000000 .. " Mil"
            else
            	ret = placeValue:format(num / 1000000) .. " Mil"-- million
            end
        elseif num >= 1000 then
            ret = placeValue:format(num / 1000) .. "k" -- thousand
        else
            ret = num .. " "-- hundreds
        end
        return ret
    end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-25-17 at 06:44 PM.
  Reply With Quote