[英]Convert scientific notation string into int
How would I convert: 我将如何转换:
s='8.833167174e+11' (str)
==> 883316717400 (int)
I tried doing int(s)
or some other 'casting' but it wasn't effective. 我尝试做
int(s)
或其他“投射”操作,但效果不佳。
As your string is a float digit you need to first convert it to float
: 由于您的字符串是浮点数字,因此需要首先将其转换为
float
:
>>> int(float(s))
883316717400
Return a floating point number constructed from a number or string x.
返回由数字或字符串x构成的浮点数。
If the argument is a string, it must contain a possibly signed decimal or floating point number, possibly embedded in whitespace.
如果参数是字符串,则它必须包含一个可能带符号的十进制或浮点数,并可能嵌入在空格中。 The argument may also be [+|-]nan or [+|-]inf.
参数也可以是[+ |-] nan或[+ |-] inf。 Otherwise, the argument may be a plain or long integer or a floating point number, and a floating point number with the same value (within Python's floating point precision) is returned.
否则,参数可以是一个普通或长整数或一个浮点数,并返回具有相同值(在Python的浮点精度内)的浮点数。 If no argument is given, returns 0.0.
如果未提供任何参数,则返回0.0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.