wpf Xaml 中的 StringFormat 格式用于货币
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5612087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
StringFormat formatting in xaml for currency
提问by Pankaj Upadhyay
I am using the following code Binding Path=InvoiceAmount, StringFormat={}{0:C0}
snippet and its working good, as i am not interested in the fraction part. It yields the result in this manner $12. But for sake of reading, can the currency format be like this $12.00instead of above.
我正在使用以下代码Binding Path=InvoiceAmount, StringFormat={}{0:C0}
片段并且它运行良好,因为我对分数部分不感兴趣。它以这种方式产生结果$12。但是为了阅读,货币格式可以像这样$12.00而不是上面。
I mean any rounding-off code for decimal part or any hack for such situation
我的意思是小数部分的任何四舍五入代码或这种情况下的任何黑客
Thanks in advance
提前致谢
采纳答案by Marat Khasanov
Any Binding can be "hacked" using IValueConverter ;)
任何绑定都可以使用 IValueConverter 来“破解”;)
You may use format like this Binding Path=InvoiceAmount, StringFormat={}{0:C0}.00
, but be careful, because this way dont care about system decimal separator.
您可以使用这样的格式Binding Path=InvoiceAmount, StringFormat={}{0:C0}.00
,但要小心,因为这种方式不关心系统小数点分隔符。
回答by NDUF
In the application I work on, we use the following and it displays $12.00
在我处理的应用程序中,我们使用以下内容并显示 $12.00
StringFormat='{}{0:c}'
Cheers
干杯
回答by Scott Nimrod
Text="{Binding Price, StringFormat='c'}"