Here's the code:
a = 0.0000224332413
a = str(a)
print(a) # 2.24332413e-05
How to make exactly str(a) = 0.0000224332413 not 2.24332413e-05 ? Thanks in advance.
Here's the code:
a = 0.0000224332413
a = str(a)
print(a) # 2.24332413e-05
How to make exactly str(a) = 0.0000224332413 not 2.24332413e-05 ? Thanks in advance.
You could use f-strings:
a = 0.0000224332413
b = f"{a:.13f}"
print(b)
Returning:
0.0000224332413
Response to the comments: closest thing to dynamically fix the number of decimals might be as follows (requires the number as string to begin with, which defeats the whole purpose):
import decimal
s = '0.0000224332413'
d = decimal.Decimal(s)
n = d.as_tuple().exponent
n *= -1
a = f"{d:.{n}f}"
print(a)
Returning:
0.0000224332413
You can use string literals or string.format(). You can use string literals or string.format().
See this article for more information: https://www.kite.com/python/answers/how-to-suppress-scientific-notation-in-python
a = 0.0000224332413
print(a) # 2.24332413e-05
b = str(a)
print(b) # 2.24332413e-05
c = f"{a:.13f}"
print(c) # 0.0000224332413
d = f"{a:.4f}"
print(d) # 0.0000
print(f"{a:f}") # 0.000022