Wednesday, 22 September 2021

Python: Convert a number to exponential format

Using string format method, we can convert a number to exponential format.

 

Example

str1 = '{0:e}'.format(10.2345)

 

Find the below working application.

 

number_to_exponential_format.py

str1 = '{0:e}'.format(10.2345)
str2 = '{0:e}'.format(100.2345)
str3 = '{0:e}'.format(1000.2345)

print('Exponential form of 10.2345 is ', str1)
print('Exponential form of 100.2345 is ', str2)
print('Exponential form of 1000.2345 is ', str3)

 

Output

Exponential form of 10.2345 is  1.023450e+01
Exponential form of 100.2345 is  1.002345e+02
Exponential form of 1000.2345 is  1.000235e+03

 

 

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment