Remove trailing zeros

后端 未结 18 962
天命终不由人
天命终不由人 2020-11-22 11:26

I have some fields returned by a collection as

2.4200
2.0044
2.0000

I want results like

2.42
2.0044
2

I t

18条回答
  •  清酒与你
    2020-11-22 11:54

    Very simple answer is to use TrimEnd(). Here is the result,

    double value = 1.00;
    string output = value.ToString().TrimEnd('0');
    

    Output is 1 If my value is 1.01 then my output will be 1.01

提交回复
热议问题