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的更多相关文章

  1. python附录-builtins.py模块str类源码(含str官方文档链接)

    python附录-builtins.py模块str类源码 str官方文档链接:https://docs.python.org/3/library/stdtypes.html#text-sequence ...

  2. 通俗易懂方式解说Python中repr(变量)和str(变量)函数的区别

    老猿在<Python中repr(变量)和str(变量)的返回值有什么区别和联系>介绍了repr(变量)和str(变量)的区别和联系(对应特殊方法__repr__和__str__),但老猿刚 ...

  3. Python中repr(变量)和str(变量)的返回值有什么区别和联系

    Python中repr(变量)和str(变量)都返回一个描述对象的字符串,二者有关联又有不同.由于Python3.0后都是新式类,我们的分析也是基于新式类进行的.基于object派生的新式类中二者之间 ...

  4. [No000066]python各种类型转换-int,str,char,float,ord,hex,oct等

    int(x [,base ]) #将x转换为一个整数 long(x [,base ]) #将x转换为一个长整数 float(x ) #将x转换到一个浮点数 complex(real [,imag ]) ...

  5. python各种类型转换-int,str,char,float,ord,hex,oct等

    int(x [,base ])         将x转换为一个整数  long(x [,base ])        将x转换为一个长整数  float(x )               将x转换到 ...

  6. 【python】python各种类型转换-int,str,char,float,ord,hex,oct等

    [python] int(x [,base ])         将x转换为一个整数 long(x [,base ])        将x转换为一个长整数 float(x )             ...

  7. python基础复习-1-2 数据类型-str、list、tuple、dict

    数据类型 数字 引号: 123 数值 '123' 字符串 整数:ini long 范围:(-2**31 - 2**31) num = 123 长整型 long (L) num = 123L 浮点型:f ...

  8. python基础之 基本数据类型,str方法和for循环

    1.概念 1.十进制转二进制,对2取余,余数倒序排列 2.字符串为空的时候,bool值为false,字符串非空就是True3.字符串转化成int时,必须是只包含数字才能转化.4.字符串转化成int时可 ...

  9. Python 中的字符串(str)、字典(dict)详解及操作方法

    一.字符串 在python中字符串是一种重要数据类型.其他数据类型分别为: 数字-number -------- int.long.float.complex这几种 字符串-string ------ ...

  10. Python 四种数值类型(int,long,float,complex)区别及转换

    Python支持四种不同的数值类型,包括int(整数)long(长整数)float(浮点实际值)complex (复数), 数字数据类型存储数值.他们是不可改变的数据类型,这意味着改变数字数据类型的结 ...

随机推荐

  1. 调度器43—migration 内核线程

    基于LInux-5.10 相关:Linux内核机制-smp_hotplug_thread:https://www.cnblogs.com/hellokitty2/p/17114737.html 一.相 ...

  2. springcloud(五) - 网关gateway

    功能介绍 springcloud gateway提供一种以路由的方式,基于Filter链的方式提供网关的基本功能.如安全.监控.限流. 网关:将不同协议的网络段连接到一起的设备,外网进入内网的入口,对 ...

  3. 如何通过使用vscode工具学习ts(typescript)

    1 如果有vscode工具可自行忽略这条:如果没有vscode工具,可进入官网http://vscode.p2hp.com/进行下载,下载过程可自行百度. 2 D盘新建文件夹随意命名为TS-LEAN, ...

  4. Andorid 11获取外部存储权限方法

    private void requestmanageexternalstorage_Permission() { if (Build.VERSION.SDK_INT >= Build.VERSI ...

  5. python checklist

    1. 常用模块:subprocess, requests, paramekio, traceback, argparse, numpy, pandas 2. 赋值传递和引用传递 python是赋值传递 ...

  6. gin面试题

    1.gin绑定前端提交的数据到结构体 json,shouldbindjson,postform,query拿到get方法或者路由拼接这些 2.gin框架中间件多个执行顺序 3.中间件实现原理 4.设计 ...

  7. java问题解答

    因为子类继承自父类,会沿用父类的东西(没被覆盖的函数以及可见的成员变量等),而这些东西子类是没有的,需要先初始化父类才能被使用 子类构造方法中调用父类构造方法,一个作用是可以给父类构造方法传递实参,给 ...

  8. vue 收藏

    html: //收藏 <el-table-column prop="isOpen" label="">                 <te ...

  9. mac上创建第一个C程序

    在mac电脑上,写C语言程序一般用终端来写,我们学习C主要是为了学习iOS的话,我们今天换Xcode来写C. 一.去App Store或者苹果开发者网站上下载Xcode.打开Xcode,创建项目. 二 ...

  10. nodejs 程序打包 打包 koa express 项目 源代码保护加密

    打包项目 几个可以 把 nodejs 打包成单个文件的库,为了方便或保护源代码,都可以尝试,打包完成需要测试,如果项目有特殊依赖,可能会失败. https://github.com/nexe/nexe ...