gpt4 book ai didi

c# - 指定格式但参数不是 IFormattable

转载 作者:太空狗 更新时间:2023-10-29 17:38:36 25 4
gpt4 key购买 nike

string listOfItemPrices = items.ToSemiColonList(item => string.Format("{0:C}", item.Price.ToString()));

我只是想将此处的价格格式化为小数点后两位。好的,所以 string.Format 没有实现 IFormattable?好的,我不确定如何解决这个问题,以便我可以在此处设置小数点(价格)的格式。

最佳答案

通过将 item.Price.ToString() 传递给 String.Format,您传递的是一个字符串,而不是小数。
由于字符串不能与格式字符串一起使用,因此会出现错误。

您需要通过删除 .ToString()Decimal 值传递给 String.Format

关于c# - 指定格式但参数不是 IFormattable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2849688/

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