decimal formatting without rounding .net

后端 未结 3 1149
悲&欢浪女
悲&欢浪女 2021-01-25 07:06

Yesterday I asked this general question about decimals and their internal precisions. Here is a specific question about the scenario I\'m trying to address.

I have colu

3条回答
  •  遇见更好的自我
    2021-01-25 07:31

    To output your required format with n=3, you could use:

    number.ToString("0.000###")
    

    With n as a parameter, then you could build a custom string format:

    string format = "0." + new string('0', n) + new string('#', 6 - n);
    s = number.ToString(format);
    

提交回复
热议问题