-----Original Message-----
From: Ian Witham <[EMAIL PROTECTED]>
Sent: Sep 18, 2007 11:39 PM
To: Christopher Spears <[EMAIL PROTECTED]>
Cc: tutor@python.org
Subject: Re: [Tutor] sales tax

As Michael points out, you need to explicitly use the round function, as the float formatting merely truncates anything after the second decimal place.

I ran across a similar problem with the int() fuction early on. Anything after the decimal point is truncated, not rounded, leading to behavior I was not expecting.

For example:

int(-1.5) == -1
int(-.5) == 0
int(.5) == 0
int(1.5) == 1

Ian

***********************************

Ian,

You may well be aware of this already, but just in case...

The behavior of the int function is not what I expected either.  I was expecting something like the greatest integer function from mathematics.

The floor() function of the math module has the behavior I expected.

Ken
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to