At 18:27 +0200 on 05/09/2004, Thomas Nyman wrote about This thing called MOD:

Hi All

I'm a bit perplexed..perhaps its a language thing,,but

the MYSQL reference manual says that

MOD
..Returns the remainder of N divided by M...
and gives an example SELECT MOD(234,10)
                     --> 4

This I do not understand. remainder of N divided by M - isn't that simply division?

I mean 234 divided by 10 does not equal 4

Yes it does. It means 23 Tens and a remainder of 4 (ones).



On my own machine..if I do SELECT MOD(23,6) I would expect 3,8333 as the result and not 5.


SInce MOD is returning something other than I expect there must be something I am missing....in other words...what is MOD returning??

Thomas

As others have explained to you, MOD has to do with INTEGER Arithmetic. Thus MOD(234,10) returns 4 since after you have taken always the 10s, you have 4 left over.


As a real world example, you have to make up some amount from 1 cent to 999 cents (such as $2.34) using ONLY Dimes and Pennies (with the rule that you have 9 Pennies and 99 dimes to use). MOD tells you how many pennies are required after you have used enough (ie: 23) dimes to get to $2.30.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to