How do I format to only include decimal if there are any

前端 未结 2 2093
长发绾君心
长发绾君心 2021-02-19 09:47

What is the best way to format a decimal if I only want decimal displayed if it is not an integer.

Eg:

decimal amount = 1000M
decimal vat = 12.50M
         


        
2条回答
  •  無奈伤痛
    2021-02-19 10:29

        decimal one = 1000M;
        decimal two = 12.5M;
    
        Console.WriteLine(one.ToString("0.##"));
        Console.WriteLine(two.ToString("0.##"));
    

提交回复
热议问题