"Toon Pieton" <[EMAIL PROTECTED]> wrote

> Something like temp = '$' + str(round(x,2)) will make x = $1.537 
> read as
> $1.54. That's perfect. However, when x = 1.3, or x = 5.0, it will 
> display
> just that: $1.3 or $5. I don't like that - I wan't 1.30 and 5.00, 
> because
> that looks much more clean and homogeneous.
>
> Is there any - not to complicated - way to do that?

Yes, use string formatting.

>>> print "$%0.2f" % 1.3
$1.30

There are a wealth of other variations, worth studying in detail.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


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

Reply via email to