[Tutor] (no subject)
Noufal Ibrahim
noufal at airtelbroadband.in
Tue Nov 28 17:30:51 CET 2006
Kopalle Narasimha wrote:
> Hello, Everyone.
>
> I have a strange problem with floating point numbers. Please help me.
> I tried the following at the python prompt:
>
> Case 1:
>>>> 4.5/2.0 #Gives quotient
> Answer: 2.25
>
> Case 2:
>>>> 4.5%2.0 #Gives Remainder
> Answer: 0.5
>
I don't think it's defined that way. When you say x%y, you are looking
for the remainder after when x is divided by y. The fractional part is a
remainder.
eg. a%b = c
4.5%2.0 = 0.5 because
2.0 * 2 + 0.5 = 4.5
(b * quotient) + c = a where quotient is not a fractional number.
It's discussed a little here http://docs.python.org/ref/binary.html
--
~noufal
More information about the Tutor
mailing list