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 (复数), 数字数据类型存储数值.他们是不可改变的数据类型,这意味着改变数字数据类型的结 ...
随机推荐
- M1 IntelliJ IDEA2022安装报错解决方法
下载地址:http://pan.jizhouyun.com/s/I3QJVzk3et 报错一:系统权限问题 报错示例: 1.XX已损坏,打不开:您应该将它移到废纸娄/已损坏 2.打不开:您应该推出磁盘 ...
- IDEA报错Error running ‘Application‘: Command line is too long解决方案
IDEA报错Error running 'Application': Command line is too long.Shorten command line for Application or ...
- springboot启动日志:Multiple Spring Data modules found, entering strict repository configuration mode
问题描述 最近启动springboot项目的时候,发现有一条日志:Multiple Spring Data modules found, entering strict repository conf ...
- MySql密码忘记怎么办?
第一步服务 net stop mysql 第二步,执行指令 mysqld --console --skip-grant-tables --user=mysql --shared-memory 第三步, ...
- 如何通过使用vscode工具学习ts(typescript)
1 如果有vscode工具可自行忽略这条:如果没有vscode工具,可进入官网http://vscode.p2hp.com/进行下载,下载过程可自行百度. 2 D盘新建文件夹随意命名为TS-LEAN, ...
- 更改ubuntu分辨率
显示器是1920*1080的,ubuntu20里没有,查了一通,修改成功,过程如下: 1.打开终端,输入xrandr, 我用的虚拟机,记下Virtual1 connected primary 1920 ...
- pgsql的round函数
不知道是我菜还是咋地,感觉pg里面用round不是很爽啊,明明在其他库能运行的,字段类型卡得太死了吧 照说float8类型还是数值,怎么就报错呢,如下 错误: 函数 round(double pre ...
- 卡片式UI设计详细指南,先收好这8条!
今天为大家分享的是「卡片设计」. 卡片是产品中常见的设计组件之一.通过卡片,可以将不同的内容分层次组合在一起.卡片式设计自带简约和易用的属性,能让页面看起来更有秩序感. 卡片作为常用的UI组件,通常由 ...
- Reactor 模式线程模型
根据Reactor的数据量和处理资源池线程数量,可以分为3钟典型实现 单Reactor单线程 单Reactor 多线程 主从Reactor 多线程
- Python接口测试request
requests安装 用pip安装requests模块 pip install requests 一.Get的使用 格式:get(url, params=None, **kwargs) Get常见查询 ...