MAUI中StringFormat的常见用法
货币格式
<TextBlock Text="{Binding Price, StringFormat='{0:C}'}" /> // $123.46 <TextBlock Text="{Binding Price, StringFormat='{0:C1}'}" /> // $123.5
前缀后缀
<TextBox Text="{Binding Price, StringFormat='单价:{0:C}元'}" /> //单价:$123.46元
固定的位数
<TextBox Text="{Binding Count, StringFormat='{0:D4}'}" /> // 0012
用 , 隔开的数字,并指定小数点后的位数
<TextBox Text="{Binding Total, StringFormat='{0:N3}'}" /> // 12,345.000
注意,一定要写分号 ' '
更多详细文档,请参考官方MAUI官方文档
String formatting - .NET MAUI | Microsoft Learn
标签:示例,StringFormat,文档,位数,MAUI,123.46 From: https://www.cnblogs.com/mauistudio/p/18005393