Imprecisão dos números de ponto flutuante + round e decimal.Decimal

This commit is contained in:
Luiz Otávio
2022-10-30 10:59:53 -03:00
parent 1e0e53b8c3
commit 20f810a1c2

14
aula55.py Normal file
View File

@@ -0,0 +1,14 @@
"""
Imprecisão de ponto flutuante
Double-precision floating-point format IEEE 754
https://en.wikipedia.org/wiki/Double-precision_floating-point_format
https://docs.python.org/pt-br/3/tutorial/floatingpoint.html
"""
import decimal
numero_1 = decimal.Decimal('0.1')
numero_2 = decimal.Decimal('0.7')
numero_3 = numero_1 + numero_2
print(numero_3)
print(f'{numero_3:.2f}')
print(round(numero_3, 2))