This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
lebuildman's profile picture

Help with Math...

Started by lebuildman, 28 April 2014 - 08:32 PM
lebuildman #1
Posted 28 April 2014 - 10:32 PM
Ok, ComputerCraft have os.time() and os.day().

os.day() return the Amount of Minecraft Days that the World Exists

I need the Following:
>A Variable will Store os.day() [local currentDay = os.day()]
>A Calc: The Var / 30 (Month) and Store it in Another Variable
(It will return a Decimal Result)
>Remove the Decimal (As if the Calc give 4,(anything) this will be 4)

With this i'm gonna use this to Expand my Code.


while true do
util.clear() --Myself API for term.clear and setPos 1 1
local exactDay = os.day()
local calc1 = <Help1>
local calc2 = <Help2>
local currentMonth = calc2 + 1
local calc3 = currentMonth * 30
local currentDay = exactDay - currentMonth

Not done yet (Will be a SuperClock Program)
MKlegoman357 #2
Posted 28 April 2014 - 11:06 PM
The division character is a slash (/). To round down a number you can use math.floor( number ).


print( 5 / 2 ) -->> 2.5

print( math.floor( 5 / 2 ) ) -->> 2

print( math.floor( 4.9 ) ) -->> 4
lebuildman #3
Posted 29 April 2014 - 04:55 PM
The division character is a slash (/). To round down a number you can use math.floor( number ).


print( 5 / 2 ) -->> 2.5

print( math.floor( 5 / 2 ) ) -->> 2

print( math.floor( 4.9 ) ) -->> 4
OMG THX!
Wait, are you the CREATOR of REDFILE?! LOL
Can I use RedFile as FileBrowser in my PDA OS?
OczkoSX #4
Posted 29 April 2014 - 05:17 PM
If you want to round numbers, from 0-4 down and 5-9 up you have to just add 0.5, like:


print( 5 / 2 ) -> 2.5
print( math.floor( 5 / 2 ) ) -> 2
print( math.floor( 5 / 2 + 0.5 ) ) -> 3
Lyqyd #5
Posted 29 April 2014 - 05:53 PM

print(-5 / 2) -> -2.5
print(math.floor(-5 / 2 + 0.5)) -> -2

Close, but not quite.
OczkoSX #6
Posted 29 April 2014 - 06:11 PM

print(-5 / 2) -> -2.5
print(math.floor(-5 / 2 + 0.5)) -> -2

Close, but not quite.

I meant positive numbers ;)/> for negative you have to minus i think
MKlegoman357 #7
Posted 29 April 2014 - 08:19 PM
OMG THX!
Wait, are you the CREATOR of REDFILE?! LOL
Can I use RedFile as FileBrowser in my PDA OS?

Your welcome :D/>

Sure you can use RedFile, just don't forget to mention that I made it and it will be OK.