iOS Question20 Mod 250

rfresh

Well-Known Member
Longtime User
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?

ilan

Expert
Longtime User
value returns 20 but the remainder is .08 so I must be doing something wrong?

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
Longtime User
Hmmm...ok let me digest that info...thank you.

Computersmith64

Well-Known Member
Longtime User
Or put more simply, I'm pretty sure Mod returns an integer (ie: a whole number).

- Colin.

Erel

B4X founder
Staff member
Longtime User
I'm pretty sure Mod returns an integer
Note that Mod in B4A and B4J supports floating point numbers as well. In B4i you can use Bit.FMod for floating points.

Replies
1
Views
569
Replies
42
Views
7K
Replies
3
Views
1K
Replies
21
Views
35K
Replies
1
Views
790