Imprecisão dos números de ponto flutuante + round e decimal.Decimal
This commit is contained in:
14
aula55.py
Normal file
14
aula55.py
Normal 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))
|
||||||
Reference in New Issue
Block a user