将小数金额格式化为字符串以便 UI 以正确的区域性信息显示的最佳方法是什么?
向 ToString 添加格式:myDecimal.ToString("#.00")
or myDecimal.ToString("C")
.
对于可为空的小数 (decimal?
)您将需要使用 .Value 属性(myNullableDecimal.Value.ToString("C")
) 或将该值转换为普通(不可为空)小数。当值为null
否则你会得到一个例外!
请参阅文档Standard https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings or Custom https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings数字格式字符串。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)