carmopereira / DU-Container-Monitor

This code is destined to Dual Universe game. This is a Container monitor for pure and ore materials. It can be used to monitor container percentages and it readouts. It was design to have a Container Hub element side each item name.
GNU General Public License v3.0
12 stars 10 forks source link

Display units on current amount #6

Open mkmarq opened 3 years ago

mkmarq commented 3 years ago

Need to show units on the current amount for clarity.

For example, right now if I see 54.0/192.0kL, it is impossible to tell from the numbers alone whether it means 54L or 54kL.

carmopereira commented 3 years ago

when i did it it seem right... but now at distance i don't like it either.

mkmarq commented 3 years ago

Direct replacement for litreParse that I think addresses the problem:

function litreParse(litre, total)
    return getValueWithUnits(litre) .. "/" .. getValueWithUnits(total)
end

function getValueWithUnits(value)
    local size = ""
    if value < 1000 then
        size = "L"
    elseif value < 1000000 then
        value = value / 1000
        size = "kL"
    else
        value = value / 1000000
        size = "kt"
    end

    return string.format("%.1f",value)..size
end

Hope it's useful :)