I have variables with values like 1.7m 1.8k and 1.2b how can I convert them to a real number value for example
1.7m = 1700000
1.8k = 1800
1.2b = 1200000000
I would define a dictionary:
tens = dict(k=10e3, m=10e6, b=10e9)
then
x='1.7m'
factor, exp = x[0:-1], x[-1].lower()
ans = int(float(factor) * tens[exp])
You might be interested in a units library like quantities or unum.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With