My numbers like 3.8485341e-06, 9.9999619e-01, 2.9322797e-20. How can I turn them into a number between 0-1. For example 0.89, 0.47, 0.14
Asked
Active
Viewed 82 times
-4
-
2They're already between 0 and 1? – Ted Brownlow Jan 10 '21 at 20:16
-
Are you trying to round them? – User 12692182 Jan 10 '21 at 20:17
-
But I need them in X.xx format, Yes actually I need to round them – Alper Alp Jan 10 '21 at 20:18
-
3Two of the three examples you gave would come out to 0.00. Is that what you want? – Ted Brownlow Jan 10 '21 at 20:20
-
Yes thank you for help and sorry for my bad English – Alper Alp Jan 10 '21 at 20:24
-
Does this answer your question? [Rounding to two decimal places in Python 2.7?](https://stackoverflow.com/questions/17470883/rounding-to-two-decimal-places-in-python-2-7) - I don't know why it specifies 2.7. The same methods still work. – wjandrea Jan 10 '21 at 20:29
-
Yes I solved the problem thank you – Alper Alp Jan 11 '21 at 06:00
2 Answers
0
If you wish to format them into a string in the format you can use f"{x:.02f}"
.
>>> x = 9.9999619e-01
>>> f"{x:.02f}"
'1.00'
Or for older versions of Python, "{:.02f}".format(x)
.

orlp
- 112,504
- 36
- 218
- 315
0
You can get rid of the exponential form with this:
a=3.8485341e-06
'{0:.20f}'.format(a)
or this
print("%.20f" % a)

Arseniy
- 680
- 5
- 10