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

Lua math - whole numbers

Started by Heroj04, 08 September 2012 - 10:59 AM
Heroj04 #1
Posted 08 September 2012 - 12:59 PM
Hey I need a program to know if a number is devisible by 3 so I need to know how to get a computer to detect if an answer is a whole number eg. 24/3=8 so true. 13/3=4.33333333333 so false
BigSHinyToys #2
Posted 08 September 2012 - 01:45 PM

if math.fmod(7,3) == 0 then
print("there is no remainder")
else
print("there is a remainder")
end
this can tell you if it divided by three correctly alter the numbers in the math.fmod() section and watch the results. if it divided it will return 0 if not it will return something else
Kingdaro #3
Posted 08 September 2012 - 04:49 PM
Just a side note, math.fmod can be replaced with the % sign, in which the above example can be performed as such:

if 7%3 == 0 then
  print("there is no remainder")
else
  print("there is a remainder")
end
Heroj04 #4
Posted 09 September 2012 - 09:13 AM

if math.fmod(7,3) == 0 then
print("there is no remainder")
else
print("there is a remainder")
end
this can tell you if it divided by three correctly alter the numbers in the math.fmod() section and watch the results. if it divided it will return 0 if not it will return something else
Just a side note, math.fmod can be replaced with the % sign, in which the above example can be performed as such:

if 7%3 == 0 then
  print("there is no remainder")
else
  print("there is a remainder")
end

thanks these both worked this will help me alot!! :D/>/>