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
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
> >>> 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
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
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
[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
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