gpt4 book ai didi

python - 字符串切片和操作

转载 作者:太空宇宙 更新时间:2023-11-03 13:55:44 25 4
gpt4 key购买 nike

价格接近 48600.0,但实际价格为 4.86 美元,所以我喜欢

last_price3 = str(x["last_price_4d"]) #48600.0
last_price2 = last_price3[0:1] + "." + last_price3[:-4]
last_price = float(last_price2)

我可以像上面那样做,但是如果价格在点前面有超过 1 个数字,比如 176.85 USD 怎么办last_price_4d 将类似于 1768500.0

谢谢

最佳答案

将价格除以 10,000 怎么样?

last_price = round(x["last_price_4d"] / 10000, 2)

关于python - 字符串切片和操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55960113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com