How to convert a floating point number 6.737 e-0.5 to the number of type 0.000023233?

How to convert a floating point number 6.737 e-0.5 to the number of type 0.000023233?
Deduce the price of the asset and it is always displayed in the format of floating point numbers, and I need regular numbers with any number of characters. Search gave nothing.
March 12th 20 at 08:12
1 answer
March 12th 20 at 08:14
Solution
You can use the f format specifier, and specify the number of decimal digits:
>>> '{:.10f}'.format(1e-10)
'0.0000000001'

A number of characters default is 6, so:
>>> '{:f}'.format(1e-6)
'0.000001'
>>> '{:f}'.format(1e-7)
'0.000000'

If you want to remove zeros after the decimal point, you can use the function rstrip:
>>> '{:f}'.format(1.1)
'1.100000'
>>> '{:f}'.format(1.1).rstrip('0')
'1.1'

By default when converting to string using str (or repr) python returns the shortest possible representation for this float, which can be exponential notation.
>>> '{:.16f}'.format(1.1)
'1.1000000000000001'
>>> 1.1
1.1
Thank You for the comprehensive answer, very helpful. - onie.Hilpert commented on March 12th 20 at 08:17
If you want to remove leading zeros....

Ah, the zeros will lead you somewhere ) - Percival.Kuvalis commented on March 12th 20 at 08:20
@Percival.Kuvalis, ugh, no leading zeros, and the zeros after the decimal point =) - Edna.Strom commented on March 12th 20 at 08:23
@Edna.Strom, there is also the term insignificant. - Percival.Kuvalis commented on March 12th 20 at 08:26

Find more questions by tags Python