Formatting a double to two decimal places

前端 未结 7 597
庸人自扰
庸人自扰 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:13

    Since you are working in currency why not simply do this:

    Console.Writeline("Earnings this week: {0:c}", answer);
    

    This will format answer as currency, so on my machine (UK) it will come out as:

    Earnings this week: £209.00

提交回复
热议问题