Jump to content




Help with Math...


  • You cannot reply to this topic
6 replies to this topic

#1 lebuildman

  • Members
  • 39 posts

Posted 28 April 2014 - 09: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)

#2 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 28 April 2014 - 10: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


#3 lebuildman

  • Members
  • 39 posts

Posted 29 April 2014 - 03:55 PM

View PostMKlegoman357, on 28 April 2014 - 10:06 PM, said:

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?

#4 OczkoSX

  • Members
  • 29 posts

Posted 29 April 2014 - 04: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


#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 29 April 2014 - 04:53 PM

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

Close, but not quite.

#6 OczkoSX

  • Members
  • 29 posts

Posted 29 April 2014 - 05:11 PM

View PostLyqyd, on 29 April 2014 - 04:53 PM, said:

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

#7 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 29 April 2014 - 07:19 PM

View Postlebuildman, on 29 April 2014 - 03:55 PM, said:

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users