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 (复数), 数字数据类型存储数值.他们是不可改变的数据类型,这意味着改变数字数据类型的结 ...
随机推荐
- 调度器42—进程exit退出流程
基于Linux-5.10 一.do_exit()简要流程 1. 执行路径 各驱动和内核机制中直接调用 SYSCALL_DEFINE1(exit, int, error_code) //exit.c 将 ...
- android系统源码编译报错问题分析处理--持续更新
一.build/make/core/base_rules.mk:232: error: packages/services/Car/service: LOCAL_BUILT_MODULE and LO ...
- 实验1task2
<实验结论> #include <stdio.h> #include <stdlib.h> int main() { int n,sum; scanf(" ...
- docker compose设置不同容器间通信
docker compose新启动了一个容器,这个时候怎么去连接到其他容器呢,去容器里面ping发现不通.一般来说是因为和其他容器没有在一个网络环境里面.首先用命令查看一下当前存在哪些网络环境. 使用 ...
- 异步串口通信协议--UART
UART(通用异步收发传输器)将由计算机内部传送过来的并行数据转换为输出的串行数据流.将计算机外部来的串行数据转换为字节,供计算机内部使用并行数据的器件使用. 在输出的串行数据流中加入奇偶校验位,并对 ...
- flannel提供的3种后端实现
UDP(flanneld封装和解封装UDP) 实现原理 缺点(性能最差) UDP模式,封装和解封装的对象是三层IP包,提供三层的Overlay网络,是Flannel最早支持的一种方式,也是性能最差的一 ...
- 浅谈JS输出中的“+”作用问题
背景(问题) web前端考试有这么一道题目(为了阅读方便和应文章的景,小编将题目进行了微调) <input type="number" value="1" ...
- MXPlayer使用第三方解码器
MXPlayer内置解码没法播放EAC3音频,可以添加第三方解码器解决 https://github.com/USBhost/MX_FFmpeg 不清楚自己什么平台选择mx_aio.zip,在MXPl ...
- 微信小程序笔记_02
在微信小程序中使用Echarts组件 github源码地址:https://github.com/ecomfe/echarts-for-weixin gitcode源码地址:https://gitco ...
- Eclipse创建maven-web项目时找不到archetype解决方法
转:https://blog.csdn.net/sunjinjuan/article/details/82943488