[Tutor] Help on float & round.
Decibels
decibelshelp@charter.net
Wed Jun 11 10:35:02 2003
Bookmarked. Thanks.
While on the subject of float and round. I originally tried to make it
save the value as, 'rounded', to save it in a database.
That doesn't seem to work and I don't think there is a way to do so.
For accuracy sake it makes sense, just wondering if there was a way.
Printing format was the most important and that has been solved, thanks.
On Wednesday 11 June 2003 01:50 am, Alan Gauld wrote:
> > What I want is for it to print at 70.70, but not be a string, but a
>
> float for
>
> > math purposes.
>
> The key here is that you only want to round for printing. So the best
> solution is a format string:
>
> print "%5.2f" % stock[2]
>
> will print the number as at least 5 characters, two of which are after
> the decimal point.
>
> Thus
>
> 7.070006 -> ' 7.07' # pads to 5 chars, rounding down
> 1237.89 -> '1237.89' # prints *at least* 5 chars
> 12.56921 -> '12.57' # rounds up
>
> Look at the first page of the Basics section ofmy tutor for more
> info on format strings.
>
> Alan G
> Author of the Learn to Program web tutor
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------------------------------------------------