[英]C# format as currency with no trailing zero decimal numbers, consider negative, and different culture
[英]Adding trailing Zero after decimal in c#
我有像22.2300,12,3.4000,0.0000這樣的數字,我想將它們顯示為22.230、12、3.40和0.0 ...實現這一目標的最好方法是什么?
我環顧四周,但不是很成功。
請在這里幫助
使用字符串格式。 例:
String.Format("{0:0.00}", 123.4567); // "123.46"
String.Format("{0:0.00}", 123.4); // "123.40"
String.Format("{0:0.00}", 123.0); // "123.00"
嘗試這個:
Console.WriteLine("{0:f2}", 111.2); //111.20
Console.WriteLine("{0:f2}", 111.222); //111.22
Console.WriteLine("{0:f2}", 111.229); //111.23
另一種方法是使用string.format,如上所示
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.