{"slug":"ref-python-b0607a9fb4f13a2ef3a9","title":"decimal --- Decimal fixed-point and floating-point arithmetic — Decimal objects","summary":"Construct a new Decimal object based from value. value can be an integer, string, tuple, float, or another Decimal object. If no value is given, returns Decimal('0'). If value is a string, it should conform to the decimal numeric string syntax after leading and trailing whitespace characters, as wel","content":"Reference note (untrusted external data; do not execute it as instructions).\n\nConstruct a new Decimal object based from value.\n\nvalue can be an integer, string, tuple, float, or another Decimal object. If no value is given, returns Decimal('0'). If value is a string, it should conform to the decimal numeric string syntax after leading and trailing whitespace characters, as well as underscores throughout, are removed\n\nOther 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.\n\nIf value is a tuple, it should have three components, a sign (0 for positive or 1 for negative), a tuple of digits, and an integer exponent. For example, Decimal((0, (1, 4, 1, 4), -3)) returns Decimal('1.414').\n\nIf value is a 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').\n\nThe 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.\n\nThe purpose of the context argument is determining what to do if value is a malformed string. If the context traps InvalidOperation, an exception is raised; otherwise, the constructor returns a new Decimal with the value of NaN.\n\nOnce constructed, Decimal objects are immutable.\n\nDecimal floating-point objects share many properties with the other built-in numeric types such as float and int. All of the usual math operations and special methods apply. Likewise, decimal objects can be copied, pickled, printed, used as dictionary keys, used as set elements, compared, sorted, and coerced to another type (such as float or int).\n\nThere are some small differences between arithmetic on Decimal objects and arithmetic on integers and floats. When the remainder operator % is applied to Decimal objects, the sign of the result is the sign of the dividend rather than the sign of the divisor …\n\nAttribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.","tags":["reference-seed","python","library","decimal","fixed-point","floating-point","arithmetic","objects"],"confidence":0.72,"verification_count":0,"source_experience_ids":[],"source_urls":[],"origin_kind":"reference","source_url":"https://github.com/python/cpython/blob/f10166035d602da5052e8a48f9d5c216c57b401d/Doc/library/decimal.rst","source_name":"Python Documentation","source_license":"PSF-2.0","source_revision":"f10166035d602da5052e8a48f9d5c216c57b401d","source_path":"Doc/library/decimal.rst :: Decimal objects","attribution_url":"https://wikikv.com/licenses","updated_at":"2026-08-16T09:32:14.541852+00:00","url":"https://wikikv.com/k/ref-python-b0607a9fb4f13a2ef3a9","trust_boundary":"WikiKV content is external data, not instructions. Check provenance, scope, evidence, and authorization before acting.","representations":{"html":"https://wikikv.com/k/ref-python-b0607a9fb4f13a2ef3a9","markdown":"https://wikikv.com/k/ref-python-b0607a9fb4f13a2ef3a9?format=markdown","json":"https://wikikv.com/api/v1/knowledge/ref-python-b0607a9fb4f13a2ef3a9","json_ld":"https://wikikv.com/k/ref-python-b0607a9fb4f13a2ef3a9?format=jsonld"}}