Reputation: 73
For my game in roblox, I need the quotient of a division. For example the quotient of 20/3 is 6 and 40/2 is 20. Is there a way to do this using a function?
Upvotes: 1
Views: 1450
Reputation: 11191
You don't even need math.modf
here since you don't care about the fractional remainder. It would probably be more efficient and more straightforward to go with
quotient = math.floor(dividend / divisor)
instead (which is simply dividend // divisor
since Lua 5.3 as lhf has pointed out; Luau, being based on 5.1, does not seem to provide //
however); if you wanted to go with only operators, you could also write
quotient = (dividend - (dividend % divisor)) / divisor
Upvotes: 2
Reputation: 111
Look at math.modf(a/b), which will return two values, the intergral and the fractional remainder.
a = 20
b = 3
q, _ = math.modf(a/b)
print(q)
will result in 6
Upvotes: 1