Remove trailing zeros

后端 未结 18 1318
天命终不由人
天命终不由人 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:51

    try like this

    string s = "2.4200";
    
    s = s.TrimStart('0').TrimEnd('0', '.');
    

    and then convert that to float

提交回复
热议问题