没时间完整写,直接上代码吧

# !usr/bin env python
# -*- coding: utf-8 -*-import re
import mathdef ConvertELogStrToValue(eLogStr):"""convert string of natural logarithm base of E to valuereturn (convertOK, convertedValue)eg:input:  -1.1694737e-03output: -0.001169input:  8.9455025e-04output: 0.000895"""(convertOK, convertedValue) = (False, 0.0)foundEPower = re.search("(?P<coefficientPart>-?\d+\.\d+)e(?P<ePowerPart>-\d+)", eLogStr, re.I)#print "foundEPower=",foundEPowerif(foundEPower):coefficientPart = foundEPower.group("coefficientPart")ePowerPart = foundEPower.group("ePowerPart")#print "coefficientPart=%s,ePower=%s"%(coefficientPart, ePower)coefficientValue = float(coefficientPart)ePowerValue = float(ePowerPart)#print "coefficientValue=%f,ePowerValue=%f"%(coefficientValue, ePowerValue)#math.e= 2.71828182846# wholeOrigValue = coefficientValue * math.pow(math.e, ePowerValue)wholeOrigValue = coefficientValue * math.pow(10, ePowerValue)#print "wholeOrigValue=",wholeOrigValue;(convertOK, convertedValue) = (True, wholeOrigValue)else:(convertOK, convertedValue) = (False, 0.0)return (convertOK, convertedValue)def parseIntEValue(intEValuesStr):# print "intEValuesStr=", intEValuesStrintEStrList = re.findall("-?\d+\.\d+e-\d+", intEValuesStr)# intEStrList = intEValuesStr.split(' ')# print "intEStrList=", intEStrListfor eachIntEStr in intEStrList:# intValue = int(eachIntEStr)# print "intValue=",intValue(convertOK, convertedValue) = ConvertELogStrToValue(eachIntEStr)#print "convertOK=%s,convertedValue=%f"%(convertOK, convertedValue)print "eachIntEStr=%s,\tconvertedValue=%f" % (eachIntEStr, convertedValue)# intEValuesStr= 2.1690427e-005 -1.1694737e-003 -6.1193734e-004
# 8.9455025e-004 -8.6277081e-004 -7.2735757e-004
# intEStrList= ['2.1690427e-005', '-1.1694737e-003', '-6.1193734e-004', '8.9455025e-004', '-8.6277081e-004', '-7.2735757e-004']
# eachIntEStr=2.1690427e-005,     convertedValue=0.014615
# eachIntEStr=-1.1694737e-003,    convertedValue=-0.058225
# eachIntEStr=-6.1193734e-004,    convertedValue=-0.112080
# eachIntEStr=8.9455025e-004,     convertedValue=0.163843
# eachIntEStr=-8.6277081e-004,    convertedValue=-0.158022
# eachIntEStr=-7.2735757e-004,    convertedValue=-0.133220if __name__ == "__main__":data_path = "/home/jianjiang/workingdir/CHA/linear-regression/data/data.txt"with open(data_path, 'r') as f:for line in f.readlines():linestr = line.strip()# print linestrparseIntEValue(linestr)

Python中将科学计数法(或以e为底的自然对数)字符串转换为float浮点数相关推荐

  1. python中将科学计数法转数字

    使用eval函数即可,

  2. Python使用科学计数法显示数字的解决方案

      大家好,我是爱编程的喵喵.双985硕士毕业,现担任全栈工程师一职,热衷于将数据思维应用到工作与生活中.从事机器学习以及相关的前后端开发工作.曾在阿里云.科大讯飞.CCF等比赛获得多次Top名次.现 ...

  3. python中科学计数法怎么表示_python科学计数法转换

    python 输出数字,如何不以科学计数法输出? 概述利用numpy设置输出选项即可 代码解析 未使用numpy设置: import time # time 时间类 print(time*time*1 ...

  4. 【安安教具】-【数学】-【科学计数法】模拟器 教你如何用python制作科学计数法模拟器 python项目小发明

    科学计数法是一种数字表现形式,可以有效对数值的显示进行折叠. 今天我们来做一款科学计数法模拟器 我们来看看这个功能有什么用处 科学计数法模拟器 这个功能的难点在于bug的处理 会遇到各种错误计算,我们 ...

  5. python实现科学计数法时间转换

    直接看效果 0 1.560091e+12 1 1.560051e+12 2 1.560089e+12 3 1.560063e+12 4 1.560079e+12 5 1.560068e+12 6 1. ...

  6. python 数值型字符串实现四舍五入 decimal_Python将科学计数法数值转换为指定精度浮点数...

    Python将科学计数法数值转换为指定精度浮点数 In [20]:money = 1190000.0 In [21]: traded_maket_value = 13824000000 In [22] ...

  7. python中的科学计数法表示

    在python中如何使用科学计数法对我们想要定义的变量进行赋值呢?请看以下代码: # -*- coding:utf-8 -*- """ author: 15025 tim ...

  8. R语言科学计数法数据改变/丢失/失准,取消科学计数法的原因和解决方法

    问题描述 如何在R中取消科学计数法 & 对R中使用科学技术法表示的数据"取消科学计数法"以后,得到的值和原来的值会不一样. 需求背景 分析留存数据时,数据库底表的字段是一个 ...

  9. excel数据导入或者导出时变为科学计数法

    在我们进行excel表格的的导入或者导出时,有时可能因为excel中的数字过长,自动转化为科学计数法,那么我们进行导入或者导出的时候就会有问题,导入或者导出之后就会发现,我们导入或者导出的数字并不像我 ...

最新文章

  1. DPlayer快速上手实验
  2. informix clob转oracle 乱码_Oracle 视图-序列-权限-表-事务
  3. 1_boostrap概述
  4. 你尽管“口嗨”,不打脸算我输
  5. 二分查找递归和非递归方法分析
  6. php软件开发--laravel框架
  7. 数据结构及算法总结(概述)
  8. MTK 驱动(65)---Android 多点触摸协议(Multi-touch Protocol)
  9. 征服Java面试官!mysql索引树结构
  10. Adobe正式在中国市场推出Creative Cloud创意应用软件
  11. cairo在Gecko上实现的路线图
  12. 天瑞地安科技集团:APP软件如何优化
  13. [Music]Candle in the Wind 1997《风中之烛》缅怀戴安娜
  14. 亿阳信通面试 亿阳信通笔试 面经大全
  15. Unity Serialization 序列化
  16. java处理excel,将xlsx转xls
  17. 一个程序员如何给LPL发弹幕加油
  18. js基本概念(上)之数据类型
  19. windows服务器迁到_Windows服务器迁移工具使用攻略
  20. 放开后经济会变好吗?越南是怎样度过的?

热门文章

  1. c/c++位操作简介--移位、位与、位或、异或
  2. 字符串转换成JSON
  3. 基于Python的时间序列异常值检测
  4. 【git】git本地如何合并分支
  5. 从零开始的异界生活(偏了)从零开始搭建lamp服务ECShop,简单快速
  6. java全栈系列之JavaSE--数组的使用025
  7. 率土之滨服务器进备战区维护多久,备战区完全解读
  8. 第一章 动量守恒定律
  9. Eclipse入门-- Eclipse的使用简介及插件开发
  10. MySQL的默认用户名和密码的什么?