Formatting a double to two decimal places

前端 未结 7 556
庸人自扰
庸人自扰 2020-11-27 06:25

I have been trying to make the answer this prints out to be to two decimal places. All the math involved has to stay at that format of two decimal places. I have tried a few

相关标签:
7条回答
  • 2020-11-27 07:15

    string.Format will not change the original value, but it will return a formatted string. For example:

    Console.WriteLine("Earnings this week: {0:0.00}", answer);
    

    Note: Console.WriteLine allows inline string formatting. The above is equivalent to:

    Console.WriteLine("Earnings this week: " + string.Format("{0:0.00}", answer));
    
    0 讨论(0)
提交回复
热议问题