我正在嘗試將資料轉換為浮點數,以便將其作為 excel 中的數字格式來對資料進行排序,我收到了錯誤。無論提到的浮點數是多少,我現在都這樣做了,但之前沒有浮點數。
def get_output_value(self, key, value, neutral=None):
display = value
if value is None and not neutral.person.is_active:
return '-', '-'
if value is None:
return float(f"${Decimal('.00')}"), float(f"${Decimal('.00')}")
if isinstance(value, Decimal):
return float(f"${intcomma(value.quantize(Decimal('.00')))}"), float(f"${intcomma(display.quantize(Decimal('.00')))}")
return float(value), display
uj5u.com熱心網友回復:
在這種情況下,答案在錯誤訊息中。'$2,464.34'是一個包含$和,字符的字串,但float()需要類似數字的輸入。
TLDR,你想要float('2464.34')但你正在給予float('$2,464.34')
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/537575.html
