In diesem Beispiel: mit Dezimal-ähnlicher PräzisionPython - warum erzeugt die Multiplikation von long und float eine dezimalähnliche Antwort?
long_ten = 10**21
print(' type(long_ten):', type(long_ten))
print(' long_ten: {:52,f}'.format(long_ten))
tenth = 0.1
print(' type(tenth):', type(tenth))
print(' float(52f): {:52.52f}'.format(tenth))
float_res = tenth * long_ten
print('\n type(float_res):', type(float_res))
print(' float(52f): {:15.52f}'.format(float_res))
Warum in einem Schwimmer ein lange und Schwimmer Ergebnis multipliziert?
type(long_ten): <type 'long'>
long_ten: 1,000,000,000,000,000,000,000.000000
type(tenth): <type 'float'>
float(52f): 0.1000000000000000055511151231257827021181583404541016
type(float_res): <type 'float'>
float(52f): 100000000000000000000.0000000000000000000000000000000000000000000000000000
Ich würde erwarten, das Ergebnis zu sein:
100000000000000005551.1151231257827021181583404541016...
Ich verstehe, warum das Ergebnis Typ float - b/c es
HINWEIS lange breiter als - das ist mit Python 2 (wenn das wichtig ist)
Zehntel geht verloren in der relativen Präzision – percusse