Remove trailing zeros

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

    This will work:

    decimal source = 2.4200m;
    string output = ((double)source).ToString();
    

    Or if your initial value is string:

    string source = "2.4200";
    string output = double.Parse(source).ToString();
    

    Pay attention to this comment.

提交回复
热议问题