Re: Floating numbers and str

2005-11-09 Thread Christian Stapfer
"Tuvas" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >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 us

Re: Floating numbers and str

2005-11-09 Thread Jeffrey Schwab
Tuvas wrote: > Wait, one more question. If the number is something like: > > 1.32042 > > It is like > "1.32 stuff" > > I would like it's size to remain constant. Any way around this? s/%g/%f >>> print "%.4f stuff" % 1.3241414515 1.3241 stuff >>> print "%.4f stuff" % 1.32042 1.3204 stuff >>>

Re: Floating numbers and str

2005-11-09 Thread Grant Edwards
On 2005-11-10, Dan Bishop <[EMAIL PROTECTED]> wrote: > Grant Edwards wrote: >> On 2005-11-09, Tuvas <[EMAIL PROTECTED]> wrote: >> >> > I would like to limit a floating variable to 4 signifigant digits, when >> > running thorugh a str command. >> >> Sorry, that's not possible. > > Technically, it is

Re: Floating numbers and str

2005-11-09 Thread Dan Bishop
Grant Edwards wrote: > On 2005-11-09, Tuvas <[EMAIL PROTECTED]> wrote: > > > I would like to limit a floating variable to 4 signifigant digits, when > > running thorugh a str command. > > Sorry, that's not possible. Technically, it is. >>> class Float4(float): ...def __str__(self): ...

Re: Floating numbers and str

2005-11-09 Thread Grant Edwards
On 2005-11-09, Tuvas <[EMAIL PROTECTED]> wrote: > Wait, one more question. If the number is something like: > > 1.32042 > > It is like > "1.32 stuff" > > I would like it's size to remain constant. Any way around this? http://www.python.org/doc/current/lib/typesseq-strings.html#l2h-211 -- Grant E

Re: Floating numbers and str

2005-11-09 Thread Fredrik Lundh
"Tuvas" <[EMAIL PROTECTED]> 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

Re: Floating numbers and str

2005-11-09 Thread Tuvas
Wait, one more question. If the number is something like: 1.32042 It is like "1.32 stuff" I would like it's size to remain constant. Any way around this? -- http://mail.python.org/mailman/listinfo/python-list

Re: Floating numbers and str

2005-11-09 Thread Grant Edwards
On 2005-11-09, Tuvas <[EMAIL PROTECTED]> wrote: > I would like to limit a floating variable to 4 signifigant digits, when > running thorugh a str command. Sorry, that's not possible. > x=.13241414515 > y=str(x)+" something here" > > But somehow limiting that to 4 sign. digits. I know that if > y

Re: Floating numbers and str

2005-11-09 Thread Tuvas
Yep, I was thinking in C, not python. Thanks for the help! -- http://mail.python.org/mailman/listinfo/python-list

Re: Floating numbers and str

2005-11-09 Thread Jeremy Moles
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

Re: Floating numbers and str

2005-11-09 Thread Jeffrey Schwab
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 %

Floating numbers and str

2005-11-09 Thread Tuvas
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