Remove trailing zeros

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

    try this code:

    string value = "100";
    value = value.Contains(".") ? value.TrimStart('0').TrimEnd('0').TrimEnd('.') : value.TrimStart('0');
    

提交回复
热议问题