Concentrating purely on the number of decimal places, something simple, like converting the number to a string might help.
>>> x = 0.00547849
>>> len(str(x).split('.')[1])
8
>>> x = 103.323
>>> len(str(x).split('.')[1])
3
It appears that I've offended the gods by offering a dirty but practical solution but here goes nothing, digging myself deeper.
If the number drops into scientific notation via the str function you won't get an accurate answer.
Picking the bones out of '23456e-05' isn't simple.
Sadly, the decimal solution also falls at this hurdle, once the number becomes small enough e.g.
>>> withdraw = decimal.Decimal('0.000000123456')
>>> withdraw
Decimal('1.23456E-7')
Also it's not clear how you'd go about getting the string for input into the decimal function, because if you pump in a float, the result can be bonkers, not to put too fine a point on it.
>>> withdraw = decimal.Decimal(0.000000123456)
>>> withdraw
Decimal('1.23455999999999990576323642514633416311653490993194282054901123046875E-7')
Perhaps I'm just displaying my ignorance.
So roll the dice, as to your preferred solution, being aware of the caveats.
It's a bit of a minefield.
Last attempt at making this even more hacky, whilst covering the bases, with a default mantissa length, in case it all goes horribly wrong:
>>> def mantissa(n):
... res_type = "Ok"
... try:
... x = str(n).split('.')[1]
... if x.isnumeric():
... res = len(x)
... else:
... res_type = "Scientific notation "+x
... res = 4
... except Exception as e:
... res_type = "Scientific notation "+str(n)
... res = 4
... return res, res_type
...
>>> print(mantissa(0.11))
(2, 'Ok')
>>> print(mantissa(0.0001))
(4, 'Ok')
>>> print(mantissa(0.0001234567890))
(12, 'Ok')
>>> print(mantissa(0.0001234567890123456789))
(20, 'Ok')
>>> print(mantissa(0.00001))
(4, 'Scientific notation 1e-05')
>>> print(mantissa(0.0000123456789))
(4, 'Scientific notation 23456789e-05')
>>> print(mantissa(0.0010123456789))
(13, 'Ok')
from decimal import Decimal; amount = Decimal(0.053)