Android Question math operator modulo (a mod b )

Gunther

Active Member
Licensed User
Longtime User
Dear all,

sometimes you need to check divisons with rest value.

The operator of Modulo (a mod b) = c is not implemented in B4A. This function is easily giving this rest value but is done as a function:

B4X:
' calculates (A mod B) and giving the rest
Sub Modulo(intA As Int, intB As Int) As Int
  If intB = 0 then return
  '
  Return intA - Floor(intA / intB) * intB
  '
End Sub

Example:
B4X:
Msgbox(Modulo(34, 3),"")
Result: 1 (since 11 * 3 = 33 rest 1)
 
Last edited:

Gunther

Active Member
Licensed User
Longtime User
Klaus right!
But is not referred in the help!
Thanks anyhow.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…