Odd decimal type behavior for ToString(IFormatProvider)

前端 未结 3 1203
南方客
南方客 2021-01-25 00:25
var numberFormat = new NumberFormatInfo();
numberFormat.NumberDecimalSeparator = \".\";
numberFormat.NumberDecimalDigits = 2;

decimal a = 10.00M;
decimal b = 10M;

Cons         


        
3条回答
  •  鱼传尺愫
    2021-01-25 00:47

    Try this:

    Console.WriteLine(String.Format("{0:0.00}", a)); 
    Console.WriteLine(String.Format("{0:0.00}", b)); 
    

    The output will have always 2 decimal cases. More examples here:

    http://www.csharp-examples.net/string-format-double/

提交回复
热议问题