Best way to display decimal without trailing zeroes

前端 未结 14 1426
终归单人心
终归单人心 2020-11-27 04:49

Is there a display formatter that will output decimals as these string representations in c# without doing any rounding?

// decimal -> string

20 -> 20         


        
14条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 05:14

    decimal val = 0.000000000100m;
    string result = val == 0 ? "0" : val.ToString().TrimEnd('0').TrimEnd('.');
    

提交回复
热议问题