Re: round() function

2010-02-25 Thread Michael Rudolf
Am 25.02.2010 16:39, schrieb Tracubik: hi all, i've this sample code: n = 4.499 str(round(n,2)) '4.5' that's right, but what i want is '4.50' to be displayed instead of '4.5'. Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. How can I solve this? Thanks in advance Nico Thi

Re: round() function

2010-02-25 Thread Stefan Behnel
Tracubik, 25.02.2010 16:39: > hi all, i've this sample code: > n = 4.499 str(round(n,2)) > '4.5' > > that's right, but what i want is '4.50' to be displayed instead of '4.5'. > Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. > > How can I solve this? Format the number

Re: round() function

2010-02-25 Thread mailing list
On 25.2.2010. 16:39, Tracubik wrote: hi all, i've this sample code: n = 4.499 str(round(n,2)) '4.5' that's right, but what i want is '4.50' to be displayed instead of '4.5'. Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. How can I solve this? Thanks in advanc

Re: round() function

2010-02-25 Thread Tim Chase
Tracubik wrote: n = 4.499 str(round(n,2)) '4.5' that's right, but what i want is '4.50' to be displayed instead of '4.5'. Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. Use string formatting: >>> "%0.2f" % round(4.499, 2) '4.50' -tkc -- http://mail.python.org/mailma

round() function

2010-02-25 Thread Tracubik
hi all, i've this sample code: >>> n = 4.499 >>> str(round(n,2)) '4.5' that's right, but what i want is '4.50' to be displayed instead of '4.5'. Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. How can I solve this? Thanks in advance Nico -- http://mail.python.org/mailman/listi

Re: round function error???

2008-07-20 Thread John Machin
On Jul 21, 12:56 am, Mark Dickinson <[EMAIL PROTECTED]> wrote: > On Jul 19, 12:20 am, John Machin <[EMAIL PROTECTED]> wrote: > > > On Jul 19, 8:05 am, Mark Dickinson <[EMAIL PROTECTED]> wrote: > > > for more information. But I'm guessing that you're > > > questioning the fact that a value that's a

Re: round function error???

2008-07-20 Thread Mark Dickinson
On Jul 19, 12:20 am, John Machin <[EMAIL PROTECTED]> wrote: > On Jul 19, 8:05 am, Mark Dickinson <[EMAIL PROTECTED]> wrote: > > for more information.  But I'm guessing that you're > > questioning the fact that a value that's apparently > > *less* than 3499.35 is rounded up to 3499.4, rather > > tha

Re: round function error???

2008-07-18 Thread John Machin
On Jul 19, 8:05 am, Mark Dickinson <[EMAIL PROTECTED]> wrote: > On Jul 18, 10:17 pm, Anthony <[EMAIL PROTECTED]> wrote: > > > Isn't this a mistake??? > > Which 'this'? That is, what were you expecting? > > If you're objecting to the fact that the second result > produces 3499.34999 instead

Re: round function error???

2008-07-18 Thread Mark Dickinson
On Jul 18, 11:15 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > No, round() return binary floats that, in general, cannot represent > decimal floats exactly.  Formatted printing gives what you expect. >  >>> '%8.2f' % x > ' 3499.35' Sure. But it's still true that the second printed value (printed a

Re: round function error???

2008-07-18 Thread Terry Reedy
Anthony wrote: Isn't this a mistake??? round(3499.349439034,44) 3499.3494390340002 round(_,2) 3499.34999 round(_,1) 3499.40001 My Python 2.5.1 spat that out.. No, round() return binary floats that, in general, cannot represent decimal floats exactly. Formatted printi

Re: round function error???

2008-07-18 Thread Mark Dickinson
On Jul 18, 10:17 pm, Anthony <[EMAIL PROTECTED]> wrote: > Isn't this a mistake??? Which 'this'? That is, what were you expecting? If you're objecting to the fact that the second result produces 3499.34999 instead of 3499.35, then no, that's not a mistake; see http://www.python.org/doc/

round function error???

2008-07-18 Thread Anthony
Isn't this a mistake??? >>> round(3499.349439034,44) 3499.3494390340002 >>> round(_,2) 3499.34999 >>> round(_,1) 3499.40001 My Python 2.5.1 spat that out.. -- http://mail.python.org/mailman/listinfo/python-list

Re: round function problem

2005-09-06 Thread Bengt Richter
On Tue, 06 Sep 2005 09:27:48 +0200, mg <[EMAIL PROTECTED]> wrote: >Hi everybody... > >We try to white scripts with Pyrhon 2.4 for an acoustic simulation and >we wrote these follow lines : > > >c = 340 340 is an integer, which is different from 340. >i =j=k= 1 >sum_ = 23 also an integer >table = [

Re: round function problem

2005-09-06 Thread Magnus Lycka
umber. Just as you can't represent ten thirds exactly as a finite decimal number (3.3...), you can't represent 3.3 exactly as a binary floating point number. 3.29999998 is about as close as you get (this is still rounded). The result of the round() function is still a floati

Re: round function problem

2005-09-06 Thread Gregory Bond
mg wrote: > Is it a bug or a control behavour ? I don't understand ?!?!?!?!... It's a case of applying different float-to-text rounding in different situations, on a variable that (even after round()) is not representable in binary floatingpoint. "print var" does one sort of string conversion

Re: round function problem

2005-09-06 Thread Fredrik Lundh
"mg" wrote: > We try to white scripts with Pyrhon 2.4 for an acoustic simulation and > we wrote these follow lines : > > > c = 340 > i =j=k= 1 > sum_ = 23 > table = [] > freq = round((c/2*(sum_)**0.5),2) > print freq > table.append([freq,(i,j,k)]) > print i,j,k,' freq',freq > for item in table: p

round function problem

2005-09-06 Thread mg
Hi everybody... We try to white scripts with Pyrhon 2.4 for an acoustic simulation and we wrote these follow lines : c = 340 i =j=k= 1 sum_ = 23 table = [] freq = round((c/2*(sum_)**0.5),2) print freq table.append([freq,(i,j,k)]) print i,j,k,' freq',freq for item in table: print item The prob