Pelokalan
Python ID
id en
Masuk
Proyek
library__decimal.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
Other Unicode decimal digits are also permitted where ``digit`` appears above. These include decimal digits from various other alphabets (for example, Arabic-Indic and Devanāgarī digits) along with the fullwidth digits ``'\uff10'`` through ``'\uff19'``. Case is not significant, so, for example, ``inf``, ``Inf``, ``INFINITY``, and ``iNfINity`` are all acceptable spellings for positive infinity.
If *value* is a :class:`tuple`, it should have three components, a sign (``0`` for positive or ``1`` for negative), a :class:`tuple` of digits, and an integer exponent. For example, ``Decimal((0, (1, 4, 1, 4), -3))`` returns ``Decimal('1.414')``.
If *value* is a :class:`float`, the binary floating-point value is losslessly converted to its exact decimal equivalent. This conversion can often require 53 or more digits of precision. For example, ``Decimal(float('1.1'))`` converts to ``Decimal('1.100000000000000088817841970012523233890533447265625')``.
The *context* precision does not affect how many digits are stored. That is determined exclusively by the number of digits in *value*. For example, ``Decimal('3.00000')`` records all five zeros even if the context precision is only three.
Decimal objects cannot generally be combined with floats or instances of :class:`fractions.Fraction` in arithmetic operations: an attempt to add a :class:`Decimal` to a :class:`float`, for example, will raise a :exc:`TypeError`. However, it is possible to use Python's comparison operators to compare a :class:`Decimal` instance ``x`` with another number ``y``. This avoids confusing results when doing equality comparisons between numbers of different types.
Return a copy of the first operand with the sign set to be the same as the sign of the second operand. For example:
For example, ``Decimal('32.100')`` and ``Decimal('0.321000e+2')`` both normalize to the equivalent value ``Decimal('32.1')``.
For example, this converts ``Decimal('123E+1')`` to ``Decimal('1.23E+3')``.
For example::
Sebagai contoh::
For example, the following code sets the current decimal precision to 42 places, performs a calculation, and then automatically restores the previous context::
Either ``0`` (the default) or ``1``. If set to ``1``, the exponent ``e`` of a :class:`Decimal` instance representable in this context is strictly limited to the range ``Emin - prec + 1 <= e <= Emax - prec + 1``. If *clamp* is ``0`` then a weaker condition holds: the adjusted exponent of the :class:`Decimal` instance is at most :attr:`~Context.Emax`. When *clamp* is ``1``, a large normal number will, where possible, have its exponent reduced and a corresponding number of zeros added to its coefficient, in order to fit the exponent constraints; this preserves the value of the number but loses information about significant trailing zeros. For example::
The :class:`Context` class defines several general purpose methods as well as a large number of methods for doing arithmetic directly in a given context. In addition, for each of the :class:`Decimal` methods described above (with the exception of the :meth:`~Decimal.adjusted` and :meth:`~Decimal.as_tuple` methods) there is a corresponding :class:`Context` method. For example, for a :class:`Context` instance ``C`` and :class:`Decimal` instance ``x``, ``C.exp(x)`` is equivalent to ``x.exp(context=C)``. Each :class:`Context` method accepts a Python integer (an instance of :class:`int`) anywhere that a Decimal instance is accepted.
If the context's trap enabler is set for the signal, then the condition causes a Python exception to be raised. For example, if the :class:`DivisionByZero` trap is set, then a :exc:`DivisionByZero` exception is raised upon encountering the condition.
Some operations are indeterminate and return ``NaN``, or if the :exc:`InvalidOperation` signal is trapped, raise an exception. For example, ``0/0`` returns ``NaN`` which means "not a number". This variety of ``NaN`` is quiet and, once created, will flow through other computations always resulting in another ``NaN``. This behavior can be useful for a series of computations that occasionally have missing inputs --- it allows the calculation to proceed while flagging specific results as invalid.
To control the defaults so that each thread will use the same values throughout the application, directly modify the *DefaultContext* object. This should be done *before* any threads are started so that there won't be a race condition between threads calling :func:`getcontext`. For example::
A: For some values, exponential notation is the only way to express the number of significant places in the coefficient. For example, expressing ``5.0E+3`` as ``5000`` keeps the value constant but cannot show the original's two-place significance.