Because it is not composed only of digits. The dot is not a digit. Ask the right question you will get the right answer.
try:
resultado = Decimal(numero)
except ValueError:
print('Não foi possível converter')
As for the question of scientific notation, it only matters when the number has to be translated into text - whether for screen printing, text file storage, inclusion in an HTML template, etc...
At this point, the number must go through the method format
- either through it explicitly, either with the new "F-strings" of Python, or by calling the function format
of Python directly (the three methods will call the method __format__
internal object Decimal
). And for the format
, just pass the formatting as "float" (letter f) for printing the Decimal
unclassified:
print("{:f}".format(Decimal(".00000001"))
or:
print(format(Decimal(".00000000001"), "f"))
I put in the Github for future reference.
As far as I can remember,
isDigit
would only return true if there were only sign characters or0-9
. In this case, the decimal point/separator is not considered as digit.– Jefferson Quesado
Maybe you’d like to see if it’s a number, no?
– Jefferson Quesado