How to write string (float) to file?
Piotr Legiecki
piotrlg at sci.pam.szczecin.pl
Tue Aug 28 05:40:06 EDT 2001
Hi
I have some simple calculations:
a=30
b=9
c=a/b
and want to store them in a file (as a string):
file.write(`c`)
Well, it is of course wrong, because 'c' is integer and truncates
everything after period.
c=float(a)/float(b)
works fine, but gives me to much places after decimal point. I need only
ie 2.
How can I tell python to give me only 2 digits after decimal point? And
of course store it in a variable.
So I want 'c' to be 3.33.
Regards
Piotr Legiecki
More information about the Python-list
mailing list