Now that I have the answer (16.800000000000001), How do I round it of
to 16.80 ? I only need it to be to the closest 1/100.
TIA
Jorge Godoy wrote:
Frank Moore <[EMAIL PROTECTED]> writes:
Johan,
You could try:
percentage = (42 * 250)/100
This gives the answer 105.
And that sounds weird, doesn't it? 42 is smaller than 250, so I'd expect it
to be less than 100% of the value... In fact, it is
42.0/250
0.16800000000000001
(42.0/250)*100
16.800000000000001
I suspect the problem is due to the fact that Python does integer division by
default:
42/250
0
So, how to make it generic?
a = 42
b = 250
a / b
0
float(a)/b
0.16800000000000001
One of the members has to be a floating point so that floating point division
is performed instead of integer division.
Be seeing you,
|
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor