Because it does not consist of only digits. The dot is not a digit. Ask the right question you will receive the right answer.
try:
resultado = Decimal(numero)
except ValueError:
print('Não foi possível converter')
update
Regarding the issue of scientific notation, this only matters when the number has to be translated into text - whether it is for screen printing, text file storage, inclusion in an HTML template, etc.
At this point, the number must pass through the format
method - either explicitly through it, either with the new Python F-strings, or by calling the format
function of Python directly (all three methods will call the __format__
Internal% of object Decimal
). And for format
, just pass the formatting as "float" (letter f) to print Decimal
without scientific notation:
print("{:f}".format(Decimal(".00000001"))
or:
print(format(Decimal(".00000000001"), "f"))