c# decimal toString() conversion with comma(,)

后端 未结 5 1159
轮回少年
轮回少年 2021-02-08 11:11

c# decimal.toString() conversion problem

Example: I have a value in decimal(.1) when I convert decimal to string using toString() it return

5条回答
  •  南笙
    南笙 (楼主)
    2021-02-08 11:34

    Then your current culture's NumberDecimalSeparator is , instead of ..

    If that's not desired you can force the dot with CultureInfo.InvariantCulture:

    decimal num = 0.1m;
    string numWithDotAsSeparator = num.ToString(CultureInfo.InvariantCulture);
    

    or NumberFormatInfo.InvariantInfo

    string numWithDotAsSeparator = num.ToString(NumberFormatInfo.InvariantInfo)
    

提交回复
热议问题