Converting double to string with N decimals, dot as decimal separator, and no thousand separator

后端 未结 7 2100
礼貌的吻别
礼貌的吻别 2020-12-28 11:43

I need to convert a decimal to a string with N decimals (two or four) and NO thousand separator:

\'XXXXXXX (dot) DDDDD\'

The problem with CultureInfo.I

7条回答
  •  轮回少年
    2020-12-28 12:18

    For a decimal, use the ToString method, and specify the Invariant culture to get a period as decimal separator:

    value.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture)
    

    The long type is an integer, so there is no fraction part. You can just format it into a string and add some zeros afterwards:

    value.ToString() + ".00"
    

提交回复
热议问题