Best way to display decimal without trailing zeroes

前端 未结 14 1455
终归单人心
终归单人心 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:22

    You can create extension method

    public static class ExtensionMethod {
      public static decimal simplify_decimal(this decimal value) => decimal.Parse($"{this:0.############}");
    }
    

提交回复
热议问题