問題:
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