Re: decimal and trunkating

2005-06-04 Thread Facundo Batista
On 2 Jun 2005 23:34:52 -0700, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > >> i want to trunkate 199.999 to 199.99 > >> getcontext.prec = 2 isn't what i'm after either, all that does > >> is E's the value. do i really have to use floats to do this? > > The precision is the total number of digi

Re: decimal and trunkating

2005-06-03 Thread Peter Hansen
chris wrote: > I'm new to Python ... and I've used decimal._round() as above. What's the > deal with using underscore methods? (A link will do if that'll save you some > typing). Generally the underscore methods provide *internal* functionality that might be used by other, more externally accessi

Re: decimal and trunkating

2005-06-03 Thread chris
"Reinhold Birkenfeld" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Peter Hansen wrote: > > Reinhold Birkenfeld wrote: > >> He is speaking of Decimals... > >> > >> d = Decimal("199.999") > >> d._round(5, decimal.ROUND_DOWN) > > > > Is one really supposed to call the underscore meth

Re: decimal and trunkating

2005-06-02 Thread Raymond Hettinger
>> i want to trunkate 199.999 to 199.99 >> getcontext.prec = 2 isn't what i'm after either, all that does >> is E's the value. do i really have to use floats to do this? The precision is the total number of digits (i.e 199.99 has 5 digit precision). Either round to that precision level or use th

Re: decimal and trunkating

2005-06-02 Thread Facundo Batista
On 6/2/05, Peter Hansen <[EMAIL PROTECTED]> wrote: > >>> d = decimal.Decimal('199.999') > >>> decimal.getcontext().rounding = decimal.ROUND_FLOOR > >>> d.quantize(decimal.Decimal('1.00')) > Decimal("199.99") > > -Peter > > (I hope this inspires someone who actually knows what he's doing with

Re: decimal and trunkating

2005-06-02 Thread Reinhold Birkenfeld
Peter Hansen wrote: > Reinhold Birkenfeld wrote: >> He is speaking of Decimals... >> >> d = Decimal("199.999") >> d._round(5, decimal.ROUND_DOWN) > > Is one really supposed to call the underscore methods like that? Umm... no, I think not ;) But I couldn't find something better. Reinhold -- htt

Re: decimal and trunkating

2005-06-02 Thread Peter Hansen
Peter Hansen wrote: > >>> d = decimal.Decimal('199.999') > >>> decimal.getcontext().rounding = decimal.ROUND_FLOOR > >>> d.quantize(decimal.Decimal('1.00')) > Decimal("199.99") Or skip changing the context and use the second argument to quantize: d.quantize(Decimal('1.00'), decimal.ROUND_FLOOR

Re: decimal and trunkating

2005-06-02 Thread Peter Hansen
Reinhold Birkenfeld wrote: > He is speaking of Decimals... > > d = Decimal("199.999") > d._round(5, decimal.ROUND_DOWN) Is one really supposed to call the underscore methods like that? -Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: decimal and trunkating

2005-06-02 Thread Peter Hansen
Timothy Smith wrote: > i want to trunkate 199.999 to 199.99 > getcontext.prec = 2 isn't what i'm after either, all that does is E's > the value. > do i really have to use floats to do this? I think you need a context with appropriate rounding set (e.g. ROUND_FLOOR?) and then use the quantize() m

Re: decimal and trunkating

2005-06-02 Thread Marc Christiansen
Timothy Smith <[EMAIL PROTECTED]> wrote: > i want to trunkate 199.999 to 199.99 > getcontext.prec = 2 isn't what i'm after either, all that does is E's > the value. > do i really have to use floats to do this? You could try this (from a script I use for my phone bill): from decimal import Decima

Re: decimal and trunkating

2005-06-02 Thread Reinhold Birkenfeld
F. Petitjean wrote: > Le Thu, 02 Jun 2005 19:59:08 +1000, Timothy Smith a écrit : >> i want to trunkate 199.999 to 199.99 > > round(199.999, 2) # 2 digits after the decimal point Wrong. This will yield 200.00. >> do i really have to use floats to do this? > > 19.999 is a float : > type(19.99

Re: decimal and trunkating

2005-06-02 Thread F. Petitjean
Le Thu, 02 Jun 2005 19:59:08 +1000, Timothy Smith a écrit : > i want to trunkate 199.999 to 199.99 round(199.999, 2) # 2 digits after the decimal point > do i really have to use floats to do this? 19.999 is a float : type(19.999) is float # ==> True -- http://mail.python.org/mailman/listin

decimal and trunkating

2005-06-02 Thread Timothy Smith
i want to trunkate 199.999 to 199.99 getcontext.prec = 2 isn't what i'm after either, all that does is E's the value. do i really have to use floats to do this? -- http://mail.python.org/mailman/listinfo/python-list