Re: [Tutor] Unexpected result from decimal

2005-01-21 Thread Kent Johnson
Jacob S. wrote: Okay, so how do I get decimal to set precision of *significant digits*? That is exactly what it is doing. getcontext().prec sets how many digits are used to represent the mantissa of the number. Have you taken any physics classes? What is 1000/7 to two significant digits? It is 14

Re: [Tutor] Unexpected result from decimal

2005-01-21 Thread Jacob S.
Okay, so how do I get decimal to set precision of *significant digits*? Why have a decimal.getcontext().prec if it doesn't provide a useful result? The number of digits in a number is irrelevant to that numbers value. It just doesn't make sense to me. I tried quantize the other day and it didn't wo

RE: [Tutor] Unexpected result from decimal

2005-01-19 Thread Tony Meyer
> >>> import decimal > >>> decimal.getcontext().prec = 2 > >>> a = decimal.Decimal(2) > >>> b = decimal.Decimal(3) > >>> 100*a/b > Decimal("67") > >>> print 100*a/b This prints "67". > try - > > a=decimal.Decimal(2.0) This will not work. You can't convert a float directly to a decimal.Decimal

Re: [Tutor] Unexpected result from decimal

2005-01-19 Thread Orri Ganel
Jacob S. wrote: Hi all,    I'm having a problem that is ticking me off. (to put it lightly) Why does decimal do this --  I thought that getcontext().prec was number of decimal places? import decimal decimal.getcontext().prec = 2 a = decimal.Decimal

Re: [Tutor] Unexpected result from decimal

2005-01-19 Thread Liam Clarke
Jacob- one slight flaw/quirk in Python is if you want floating point computations you have to specify a floating point. >>> import decimal >>> decimal.getcontext().prec = 2 >>> a = decimal.Decimal(2) >>> b = decimal.Decimal(3) >>> 100*a/b Decimal("67") >>> print 100*a/b try - a=decimal.Decimal

Re: [Tutor] Unexpected result from decimal

2005-01-19 Thread Tim Peters
[Jacob S.] >I'm having a problem that is ticking me off. (to put it lightly) > Why does decimal do this -- I thought that getcontext().prec > was number of decimal places? It's unclear what you mean by "decimal places". From context, you _appear_ to mean "number of decimal digits after the r

[Tutor] Unexpected result from decimal

2005-01-19 Thread Jacob S.
Hi all, I'm having a problem that is ticking me off. (to put it lightly) Why does decimal do this -- I thought that getcontext().prec was number of decimal places? import decimal decimal.getcontext().prec = 2 a = decimal.Decimal(2) b = decimal.Decimal(3) 100*a/b Decimal("67") print 100*a/b 67