简体   繁体   English

ValueError: 类型“str”的对象的格式代码“e”未知

[英]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.

相关问题 ValueError:类型为“ str”的对象的未知格式代码“ g” - ValueError: Unknown format code 'g' for object of type 'str' ValueError:类型为“str”的 object 的未知格式代码“f” - ValueError: Unknown format code 'f' for object of type 'str' 在代码中格式化不断导致 ValueError: Unknown format code 'f' for object of type 'str'? - Formatting in a code constantly causes the ValueError: Unknown format code 'f' for object of type 'str'? ValueError:类型为&#39;str&#39;的对象的未知格式代码&#39;f&#39;-为什么第二次却不是第一次? - ValueError: Unknown format code 'f' for object of type 'str' - why do I get this the second time but not the first time? Rc4 decrypt ValueError:object 类型为“str”的未知格式代码“x” - Rc4 decrypt ValueError: Unknown format code 'x' for object of type 'str' 类型“ str”的对象的未知格式代码“ b” - Unknown format code 'b' for object of type 'str' “str”类型对象的未知格式代码“g” - Unknown format code 'g' for object of type 'str' 类型为&#39;str&#39;的对象的未知格式代码&#39;f&#39;-Folium - Unknown format code 'f' for object of type 'str'- Folium 卡在 python 代码中进行加密。 错误是“str”类型的 object 的未知格式代码“x” - stuck in a python code for encryption. error is Unknown format code 'x' for object of type 'str' 在我的情况下,“str”类型的 object 的“未知格式代码 'f' 是什么意思? - What does "Unknown format code 'f' for object of type 'str' mean in my case?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM