24 posts
Posted 28 May 2015 - 05:33 PM
Just a quick one ive made a small program displaying multiple drums/tanks on a monitor displaying the amount and the capacity
but sadly i do not know how to calculate the fill percentage
any help please?
3057 posts
Location
United States of America
Posted 28 May 2015 - 05:35 PM
Percentage is calculated as:
Current Amount / Maximum Amount * 100
8543 posts
Posted 28 May 2015 - 05:37 PM
Full percentage is a pretty simple formula. It's the ratio of the amount to the capacity expressed as a value to 100, or:
amount / capacity = x / 100
Simply multiply both sides by 100 to isolate x and solve:
amount * 100 / capacity = x
Or, in Lua code:
local percentage = amount * 100 / capacity
24 posts
Posted 28 May 2015 - 05:47 PM
well i feel dumb……Cheers dude it works i was trying a bit more complex code but the simple one works just as good
and Thank you too Lyqyd that code also worked
A bit hard to see but there is 18 drums and is now showing the amount capacity and fill percentage
Edited on 28 May 2015 - 03:48 PM
24 posts
Posted 28 May 2015 - 08:24 PM
Okay so i got a pretty decent code now but i would also like to ask another question
How do i detect a empty drum without it giving a nil value error?
3057 posts
Location
United States of America
Posted 28 May 2015 - 09:25 PM
Don't assume something is a table until you've checked that it isn't nil.
7083 posts
Location
Tasmania (AU)
Posted 28 May 2015 - 11:31 PM