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?

Asked By: diviserbyzero

||

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')
>>> 
Answered By: Amir reza Riahi

You could remove it in multiple ways:

  1. Change to int type:

int(b)
178405961588245203517440

  1. Using Decimal()

from decimal import Decimal
Decimal(b)
178405961588245203517440

  1. Using format()

out=format(b, ".2f")
print(out)
178405961588245203517440.00 //but is a string 

Answered By: AlekhyaV – Intel
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.