The module is also very useful if for some crazy reason you need to do integer division and get a decimal number, and you cannot convert an integer to a number that supports decimal division, or if you need to return a part instead of a decimal fraction.
I will use % as a module operator
for example
2/4 = 0
where is it done
2/4 = 0 and 2 % 4 = 2
So, you can be really crazy and say that you want to allow the user to enter a numerator and a divisor, and then show the result as an integer, and then a fractional number.
whole Number = numerator/divisor fractionNumerator = numerator % divisor fractionDenominator = divisor
Another case where modulo separation is useful is to increase or decrease the number, and you want to shift the number to a certain range of numbers, but when you get to the top or bottom, you donβt just want to stop, you want the loop up or down at the top of the list, respectively.
Imagine a function in which you iterate over an array.
Function increase Or Decrease(variable As Integer) As Void n = (n + variable) % (listString.maxIndex + 1) Print listString[n] End Function
The reason this is n = (n + variable)% (listString.maxIndex + 1) should consider the max account.
These are just some of the things that I had to use for modulation in my programming, not only for desktop applications, but also in the environment of robotics and modeling.
msarchet Apr 09 '10 at 17:13 2010-04-09 17:13
source share