Floating numbers and str

Christian Stapfer nil at dev.nul
Thu Nov 10 06:18:27 CET 2005

"Tuvas" <tuvas21 at gmail.com> wrote in message 
news:1131565949.678342.39890 at g44g2000cwa.googlegroups.com...
>I would like to limit a floating variable to 4 signifigant digits, when
> running thorugh a str command. Ei,
> x=.13241414515
> y=str(x)+" something here"
> But somehow limiting that to 4 sign. digits. I know that if you use the
> print statement, you can do something like %.4d, but how can I do this
> with converting the number to a string? Thanks!

from scipy import round

print round(0.13241414515,4)


More information about the Python-list mailing list