How do I convert numbers with e to digits only?
Question:
I want to convert numbers like 1.28e+21 to a long digits only number but the following code doesn’t make a difference.
n = 1.28e+21 b = 1.28*10**21 print(b)
b still has an e.
How do I get rid of e?
Answers:
These numbers in exponential format are from type float
in python.You can use int
to convert it to an integer.
>>> n = int(1.28e+21)
>>> n
1280000000000000000000
You can also use decimal
module like this:
>>> import decimal
>>> decimal.Decimal(1.28e+21)
Decimal('1280000000000000000000')
>>>
You could remove it in multiple ways:
- Change to int type:
int(b)
178405961588245203517440
- Using Decimal()
from decimal import Decimal
Decimal(b)
178405961588245203517440
- Using format()
out=format(b, ".2f")
print(out)
178405961588245203517440.00 //but is a string
I want to convert numbers like 1.28e+21 to a long digits only number but the following code doesn’t make a difference.
n = 1.28e+21 b = 1.28*10**21 print(b)
b still has an e.
How do I get rid of e?
These numbers in exponential format are from type float
in python.You can use int
to convert it to an integer.
>>> n = int(1.28e+21)
>>> n
1280000000000000000000
You can also use decimal
module like this:
>>> import decimal
>>> decimal.Decimal(1.28e+21)
Decimal('1280000000000000000000')
>>>
You could remove it in multiple ways:
- Change to int type:
int(b)
178405961588245203517440
- Using Decimal()
from decimal import Decimal
Decimal(b)
178405961588245203517440
- Using format()
out=format(b, ".2f")
print(out)
178405961588245203517440.00 //but is a string