[英]ValueError: Unknown format code 'e' for object of type 'str'
How to solve this error I am trying to get the number of coins for usdt For example the number of the quantity I want to buy against the usdt: 17.493796277071922如何解决这个错误我正在尝试获取usdt的硬币数量例如我想对usdt购买的数量:17.493796277071922
def format_value(valuetoformatx,fractionfactorx):
value = valuetoformatx
fractionfactor = fractionfactorx
Precision = abs(int(f'{fractionfactor:e}'.split('e')[-1]))
FormattedValue = float('{:0.0{}f}'.format(value, Precision))
return FormattedValue
def pairPriceinfo(ticker,client):
info = client.get_symbol_info(ticker)
minPrice = pd.to_numeric(info['filters'][0]['minPrice'])
return minPrice
def pairQtyinfo(ticker,client):
info = client.get_symbol_info(ticker)
minQty = pd.to_numeric(info['filters'][2]['minQty'])
return minQty
*error*
Precision= abs(int(f'{fractionfactor:e}'.split('e')[-1]))
ValueError: Unknown format code 'e' for object of type 'str'
*Please do not close the question *请不要关闭问题
The error message tells you exactly what's wrong.错误消息准确地告诉您出了什么问题。 I suggest learning how to read Python's error messages, as oftentimes they are sufficient for debugging.
我建议学习如何阅读 Python 的错误消息,因为它们通常足以进行调试。
In [1]: f"{'1634':e}"
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-b8ad0a2d3495> in <module>
----> 1 f"{'1634':e}"
ValueError: Unknown format code 'e' for object of type 'str'
In [2]: f"{1634:e}"
Out[2]: '1.634000e+03'
The problem is caused by fractionfactor
being a string, and not a number, as described by the ValueError
message:问题是由
fractionfactor
是字符串而不是数字引起的,如ValueError
消息所述:
Unknown format code 'e' for object of type 'str'
“str”类型对象的未知格式代码“e”
Strings are not numbers, so it doesn't make any sense to ask Python to display a string in scientific notation.字符串不是数字,因此让 Python 以科学记数法显示字符串没有任何意义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.