📜  Python程序将指数转换为浮点数

📅  最后修改于: 2022-05-13 01:54:18.321000             🧑  作者: Mango

Python程序将指数转换为浮点数

给定一个指数格式的数字,任务是编写一个Python程序将数字从指数格式转换为浮点数。指数数是表示数字的一种方式。

例子:

Input: 1.900000e+01
Output: 19.0

Input: 2.002000e+03
Output: 2002.0

Input: 1.101020e+05
Output: 110102.0

方法:

  • 首先,我们将声明一个指数数并将其保存在一个变量中。
  • 然后我们将使用float()函数将其转换为 float 数据类型。
  • 然后我们将打印转换后的数字。

句法:

float(x)

float() 方法用于从数字或字符串返回浮点数。

例子:

Python3
# Python program to convert exponential to float
  
# Declaring the exponential number
exp_number = "{:e}".format(110102)
  
# Converting it to float data type
float_number = float(exp_number)
  
# Printing the converted number
print("Exponent Number:",exp_number)
print("Float Number:",float_number)


输出:

Exponent Number: 1.101020e+05
Float Number: 110102.0