Formatting a double to two decimal places

前端 未结 7 594
庸人自扰
庸人自扰 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 06:57

        double d =  3.1493745;
        string s = $"{d:0.00}"; // or $"{d:#.##}"
        Console.WriteLine(s); // Displays 3.15
    

提交回复
热议问题