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
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
"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
>> 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
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
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
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
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
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
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
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
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
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
13 matches
Mail list logo