Floating numbers and str

Jeremy Moles jeremy at emperorlinux.com
Wed Nov 9 07:01:31 EST 2005


I think you answered your own question. :)

x = 0.12345678
y = "%.4f something here" % x

On Wed, 2005-11-09 at 11:52 -0800, Tuvas wrote:
> 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!
> 




More information about the Python-list mailing list