Formatted Output - Floating Point Numbers
Tyler Eaves
usenet at coastergames.net
Sat Nov 16 17:37:45 EST 2002
David Marshall wrote:
> Im new to python and I was wondering if anybody could tell me how to
> modify the output to only obtaiu 2 decimal places.
>
> the section of my program that needs modification
>
> display.divide(57,7) # I only want 2 decimal places returned
>
> I have a module called display and my function divide() returns the
> result of the two numbers divided. However, I only want this number to
> two decimal places.
>
> I have tried: round(display.divide(57,7) [,2])
> But this results in an error message saying invalid syntax
>
>
> Any help would be much appreciated
Use the % operator.
IE:
print "%.2f" % yourFloat
--
Tyler Eaves
More information about the Python-list
mailing list