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.

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.

asked March 12th 20 at 08:12

1 answer

answered on

Solution

You can use the f format specifier, and specify the number of decimal digits:

A number of characters default is 6, so:

If you want to remove zeros after the decimal point, you can use the function

By default when converting to string using str (or repr) python returns the shortest possible representation for this float, which can be exponential notation.

```
>>> '{:.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
```

Find more questions by tags Python

Ah, the zeros will lead you somewhere ) - Percival.Kuvalis commented on March 12th 20 at 08:20

insignificant. - Percival.Kuvalis commented on March 12th 20 at 08:26