« Refa Tandoori Indian Restaurant, Melksham | Main | Upgrade Mac OSX to Leopard, Web Server Apache httpd config lost »

November 28, 2007

Question on division (Java) - Also Perl, PHP, Python ...

Q:

What's the difference between % and /?

A:

/ returns the result of a division
% returns the remainder when you do a division.

Divide 18 by 7 you get 2, with a remainder of 4 (i.e. 4 left over).

so 18/7 give 2, and 18%7 gives 4.


And from Tcl/Tk and Expect... you can see the float v integer considerations of a division!

% expr 18 / 7
2
% expr 18. / 7
2.57142857143
% expr 18 % 7
4
%

Posted by gje at November 28, 2007 02:47 PM

Comments

Well House Consultants Ltd. Copyright 2010