Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct conversion of float to string #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

khanxmetu
Copy link

Hi,
The difference in float and Decimal floating point representations may lead to discrepancies when converting from one type to another.
Here is an excerpt from https://docs.python.org/3/library/decimal.html#module-decimal:

If 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').

Therefore it is best to directly convert float type to string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant