decimal formatting without rounding .net

后端 未结 3 1109
悲&欢浪女
悲&欢浪女 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:32

    You should be able to do this by formatting the value as such:

    var str = num.ToString("#0.000#####");
    

    The number of 0s determines the minimum number of digits, and the number of 0s plus #s the maximum number of digits. I'm not sure if you actually want the maximum, but I believe this is the closest you'll get. You could of course just set it to an arbitrary (large) number.

提交回复
热议问题