CATboardBETA
CATboardBETA

Reputation: 530

Is it possible to have more than 15 decimal digits in a float without Decimal module?

Is it possible to store more than 15 digits in a float.
For example, I have this float phi.

Example:

phi = 21.618033988749894848204586834365 # 30 decimal digits

print(phi) # -> ~21.618033988749893, 15 imprecise decimal digits

How can I guarantee I get more than 15 accurate digits from this float, without using the Decimal class?

NOTE: I know that this is not applicable, as Decimal is built into Python. I am leaving it open for reference to others with a similar situation, not realizing Decimal is a builtin.

Upvotes: 2

Views: 1220

Answers (1)

user2357112
user2357112

Reputation: 280390

Floats are fixed-precision. They physically cannot store the amount of data you're trying to stuff into them. You will have to use an arbitrary-precision data type; decimal.Decimal is one, but there are others that may be more useful depending on what you're trying to do.

Upvotes: 2

Related Questions