rfresh Well-Known Member Licensed User Longtime User Jan 3, 2019 #1 20 divided by 250 == 0.08 I'm trying to get the remainder: value = 20 Mod 250 value returns 20 but the remainder is .08 so I must be doing something wrong?
20 divided by 250 == 0.08 I'm trying to get the remainder: value = 20 Mod 250 value returns 20 but the remainder is .08 so I must be doing something wrong?
klaus Expert Licensed User Longtime User Jan 3, 2019 #2 What you expect is : Value = (20 Mod 250) / 250 The Mod funtion returns the reminder. 20 Mod 250 = 20 270 Mod 250 = 20 520 Mod 250 = 20 Upvote 0
What you expect is : Value = (20 Mod 250) / 250 The Mod funtion returns the reminder. 20 Mod 250 = 20 270 Mod 250 = 20 520 Mod 250 = 20
ilan Expert Licensed User Longtime User Jan 3, 2019 #3 rfresh said: value returns 20 but the remainder is .08 so I must be doing something wrong? Click to expand... i am nut sure i understand what you mean. MOD is not equal to DIVIDE mod (as you mentioned) is the remainder of a number substract the "mod" number like 13 mod 3 will do 13 - 3 = 10 10 - 3 = 7 7 - 3 = 4 4 - 3 = 1 1 - 3 < 0 so the remainder is 1 as long the number can substract the "mod" number but still stay positive the mod function will do it. when you get a negative number the mod function will stop and return the remained number. 20 mod 250 will try to substract 250 from 20 so it will do 20 - 250 what will return -230 so its a negative number so the mod will stop and return the last positive number. another example 27 mod 12 will do 27 - 12 = 15 15 - 12 = 3 3 - 12 = -9 !!!! MOD: oh no its a negative number return back to the last positive number and thats 3 so 27 mod 12 = 3 ! Upvote 0
rfresh said: value returns 20 but the remainder is .08 so I must be doing something wrong? Click to expand... i am nut sure i understand what you mean. MOD is not equal to DIVIDE mod (as you mentioned) is the remainder of a number substract the "mod" number like 13 mod 3 will do 13 - 3 = 10 10 - 3 = 7 7 - 3 = 4 4 - 3 = 1 1 - 3 < 0 so the remainder is 1 as long the number can substract the "mod" number but still stay positive the mod function will do it. when you get a negative number the mod function will stop and return the remained number. 20 mod 250 will try to substract 250 from 20 so it will do 20 - 250 what will return -230 so its a negative number so the mod will stop and return the last positive number. another example 27 mod 12 will do 27 - 12 = 15 15 - 12 = 3 3 - 12 = -9 !!!! MOD: oh no its a negative number return back to the last positive number and thats 3 so 27 mod 12 = 3 !
rfresh Well-Known Member Licensed User Longtime User Jan 3, 2019 #4 Hmmm...ok let me digest that info...thank you. Upvote 0
Computersmith64 Well-Known Member Licensed User Longtime User Jan 6, 2019 #5 Or put more simply, I'm pretty sure Mod returns an integer (ie: a whole number). - Colin. Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jan 7, 2019 #6 Computersmith64 said: I'm pretty sure Mod returns an integer Click to expand... Note that Mod in B4A and B4J supports floating point numbers as well. In B4i you can use Bit.FMod for floating points. Upvote 0
Computersmith64 said: I'm pretty sure Mod returns an integer Click to expand... Note that Mod in B4A and B4J supports floating point numbers as well. In B4i you can use Bit.FMod for floating points.