gpt4 book ai didi

c# - DataFormatString for percent with decimals only when needed?

转载 作者:行者123 更新时间:2023-11-30 19:02:33 25 4
gpt4 key购买 nike

我正在尝试通过 MVC 在 EF 代码优先属性上使用这些: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

具体来说:

[DisplayFormat(DataFormatString="##.##%")]
public double? PercentOfSomething {get;set;}

如何让 .2345 显示为 23.45% 和 .2 显示为 20%换句话说,如果有一位,则只显示小数点,最多两位。

就像现在一样,它只显示格式字符串“##.##%”。我猜 DisplayFormat 属性可能不支持这些类型的格式字符串。

最佳答案

我认为你应该使用“{0:##.##%}”而不是 ##.##%

关于c# - DataFormatString for percent with decimals only when needed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11564008/

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