Is there a function in python that could convert decimal to 3-4 significant digits, eg:
55820.02932238298323 to 5.58e4
Many thanks in advance.
Is there a function in python that could convert decimal to 3-4 significant digits, eg:
55820.02932238298323 to 5.58e4
Many thanks in advance.
If by "convert to" you mean that you want a string formatted like that, you can use the %e
format option:
>>> '%.2e' % 55820.02932238298323
'5.58e+04'
If this is for output purposes you can just use string formatting:
>>> "%.2e" % 55820.02932238298323
'5.58e+04'
>>> "{:.2e}".format(55820.02932238298323)
'5.58e+04'
If you want the rounded value to be a float
take a look at this question.