python:包含’e’和‘-’的 str 转 float
from functools import reduce def str2float(s):
s = s.split('.')
a = s[0]
b = s[1]
if a[0] == '-':
a = a[1:]
front = reduce(lambda x,y:y+x*10,map(int,a))
a = 0
if 'e' in b:
print('a')
for i in b:
a += 1
if i == 'e':
c = b[a+1:]
middle = reduce(lambda x,y:y+x*10,map(int,c))
b = b[:a-1]
buttom = reduce(lambda x,y:y+x*10,map(int,b))
result = (front + buttom / 10 ** (len(b))) / 10 ** middle
result = -result
print(result)
return result
else:
print('b')
buttom = reduce(lambda x, y: y + x * 10, map(int, b))
result = front + buttom / 10 ** (len(b))
result = -result
print(result)
return result
else :
front = reduce(lambda x, y: y + x * 10, map(int, a))
a = 0
if 'e' in b:
print('c')
for i in b:
a += 1
if i == 'e':
c = b[a+1:]
middle = reduce(lambda x,y:y+x*10,map(int,c))
b = b[:a-1]
buttom = reduce(lambda x,y:y+x*10,map(int,b))
result = (front + buttom / 10 ** (len(b))) / 10 ** middle
print(result)
return result
else:
print('d')
buttom = reduce(lambda x, y: y + x * 10, map(int, b))
result = front + buttom / 10 ** (len(b))
print(result)
return result

python:包含’e’和‘-’的 str 转 float的更多相关文章
- python附录-builtins.py模块str类源码(含str官方文档链接)
python附录-builtins.py模块str类源码 str官方文档链接:https://docs.python.org/3/library/stdtypes.html#text-sequence ...
- 通俗易懂方式解说Python中repr(变量)和str(变量)函数的区别
老猿在<Python中repr(变量)和str(变量)的返回值有什么区别和联系>介绍了repr(变量)和str(变量)的区别和联系(对应特殊方法__repr__和__str__),但老猿刚 ...
- Python中repr(变量)和str(变量)的返回值有什么区别和联系
Python中repr(变量)和str(变量)都返回一个描述对象的字符串,二者有关联又有不同.由于Python3.0后都是新式类,我们的分析也是基于新式类进行的.基于object派生的新式类中二者之间 ...
- [No000066]python各种类型转换-int,str,char,float,ord,hex,oct等
int(x [,base ]) #将x转换为一个整数 long(x [,base ]) #将x转换为一个长整数 float(x ) #将x转换到一个浮点数 complex(real [,imag ]) ...
- python各种类型转换-int,str,char,float,ord,hex,oct等
int(x [,base ]) 将x转换为一个整数 long(x [,base ]) 将x转换为一个长整数 float(x ) 将x转换到 ...
- 【python】python各种类型转换-int,str,char,float,ord,hex,oct等
[python] int(x [,base ]) 将x转换为一个整数 long(x [,base ]) 将x转换为一个长整数 float(x ) ...
- python基础复习-1-2 数据类型-str、list、tuple、dict
数据类型 数字 引号: 123 数值 '123' 字符串 整数:ini long 范围:(-2**31 - 2**31) num = 123 长整型 long (L) num = 123L 浮点型:f ...
- python基础之 基本数据类型,str方法和for循环
1.概念 1.十进制转二进制,对2取余,余数倒序排列 2.字符串为空的时候,bool值为false,字符串非空就是True3.字符串转化成int时,必须是只包含数字才能转化.4.字符串转化成int时可 ...
- Python 中的字符串(str)、字典(dict)详解及操作方法
一.字符串 在python中字符串是一种重要数据类型.其他数据类型分别为: 数字-number -------- int.long.float.complex这几种 字符串-string ------ ...
- Python 四种数值类型(int,long,float,complex)区别及转换
Python支持四种不同的数值类型,包括int(整数)long(长整数)float(浮点实际值)complex (复数), 数字数据类型存储数值.他们是不可改变的数据类型,这意味着改变数字数据类型的结 ...
随机推荐
- 下载安装i5ting_toc
全部都是以管理员身份运行powershell 1.打开powershell之后输入命令npm i i5ting_toc -g 这样就全局安装了 2.set-ExecutionPolicy Remote ...
- 国产低功耗Soc蓝牙语音遥控器芯片HS6621 /OM6621
随着物联网技术不断发展,家用电器往智能化方向持续迭代,使用红外遥控器这种传统的互动方式已经满足不了实际的使用需求,蓝牙语音遥控器作为人机交互新载体,逐渐取代传统红外遥控器成为家居设备的标配.相比于传统 ...
- python快速制作可视化报表
- paddle 错误(ValueError: all input arrays must have the same shape)
参考:voc数据集执行eval.py命令报错 · Issue #3456 · PaddlePaddle/PaddleDetection (github.com) 配置文件加这两行: EvalReade ...
- 使用shell定时执行脚本
yum install crontabs //安装 #检查安装crontab -V #服务操作service crond start //启动服务service crond stop //关闭服务se ...
- 02 流程控制之while循环
# 1.循环的语法与基本使用'''print(1)while 条件: 代码1 代码2 代码3print(3)''' # count=0# while count < 5: # 5 < 5# ...
- SQL执行定时任务JOB,包教包会
什么是JOB? 数据库中可以定时执行任务的功能组件,那就是JOB. JOB的作用 它可以按我们设置好的参数定时执行查询语句或存储过程,特别适合一些每天,每周,每月,每年这种需要循环执行任务的场景,当然 ...
- celery学习
1.清空队列:celery -A 项目名称 purge 2.原理参考 https://www.cnblogs.com/sui776265233/p/10004679.html 消息中间件(messa ...
- mysql redis 开启远程访问
springboot 加载外部yml nohup java -jar warehouse-0.0.1-SNAPSHOT.jar --Dspring.config.location=/root/www/ ...
- 玩玩 Visual Studio Code 和 MSYS2
注意:为了便于理解本文内容,您可能需要一些前置知识,例如命令行操作,编译器操作,路径操作,环境变量操作,vscode操作-- 众所周知 Visual Studio Code 是一个优秀的编辑器. 众所 ...