C# 从 .ToString("c") 格式的数字中删除尾随小数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/774399/
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
Removing trailing decimals from a .ToString("c") formatted number
提问by Scott Schulthess
Basically I am formatting numbers like so
基本上我像这样格式化数字
price.ToString("c")
The result is $615.00 in english and 615,00 $ in french.
结果是英语为 615.00 美元,法语为 615.00 美元。
My desired result, however, is $615 and 615 $, respectively. How can I attain this, while still taking advantage of .nets localization handling?
然而,我想要的结果分别是 615 美元和 615 美元。我怎样才能做到这一点,同时仍然利用 .nets 本地化处理?
采纳答案by John Rasch
If you don't mind rounding...
如果你不介意四舍五入...
price.ToString("c0")