Jump to content




Lua math - whole numbers


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

#1 Heroj04

  • Members
  • 32 posts

Posted 08 September 2012 - 11:59 AM

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

#2 BigSHinyToys

  • Members
  • 1,001 posts

Posted 08 September 2012 - 12: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

#3 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 08 September 2012 - 03: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


#4 Heroj04

  • Members
  • 32 posts

Posted 09 September 2012 - 08:13 AM

View PostBigSHinyToys, on 08 September 2012 - 12:45 PM, said:

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

View PostKingdaro, on 08 September 2012 - 03:49 PM, said:

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/>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users