normality
normality copied to clipboard
Correct conversion of float to string
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.