Odd decimal type behavior for ToString(IFormatProvider)

前端 未结 3 1200
南方客
南方客 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 01:11

    The NumberDecimalDigits property is used with the "F" and "N" standard format strings, not the ToString method called without a format string.

    You can use:

    Console.WriteLine(a.ToString("N", numberFormat));
    

提交回复
热议问题