问题:
How do I format a Double
to a String
in C# so as to have only two decimal places?如何在 C# 中将Double
格式化为String
以便只有两位小数?
If I use String.Format("{0:0.00}%", myDoubleValue)
the number is then rounded and I want a simple truncate without any rounding.如果我使用String.Format("{0:0.00}%", myDoubleValue)
然后对数字进行四舍五入,我想要一个没有任何四舍五入的简单截断。 I also want the conversion to String
to be culture sensitive.我还希望转换为String
是文化敏感的。
解决方案:
参考一: https://en.stackoom.com/question/AINr参考二: https://stackoom.com/question/AINr