Issue
Good afternoon. I'm constructing a binary module for a platform that uses lua for developers, and I'm accomplishing this by successive division from this video to get the remainder as an alternative, however, I am at a roadblock here to detect a decimal point.
My goal is to detect a number that has a decimal point and use successive division like the video to index into a table and loop through, for my binary module. I've tried to check if ceiling a number (that's a float) would equal rounding it + .5, this works, however, it isn't a long term solution IMO.
for _, value in pairs({4.2, 4.1, 4.9, 5}) do --> loops through a table containing numbers.
if math.ceil(value) == math.round(value+.5) then --> checks if a number ceils and equals?
local b = script:SetAttribute(tostring('Remainder'), value) --> prints on first 3 elements.
else
print('no remainder') --> prints on last element of table, '5'.
end
end
I have also tried dividing in a loop, wasn't a good way.
I've searched up some of my problems on here, google, or lua websites, none had what I was looking for, or were simply not suitable for my codebase. So, how would I accomplish checking if a number has a decimal or a remainder?
Solution
Use modulo/remainder division(%) . What that does is it checks and gives you the remainder. For instance 20%6 would give you "2" as the answer since 20÷6 = 3 remainder 2.
Answered By - Kamva Cewu Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.