Math.Ceiling 提示

Math.Ceiling Tips

如何将 3.79 的金额四舍五入为 3.80

double number = Math.Ceiling(3.79); //Gives me 4, but I need 3.80

这个问题很简单,但我不知道如何实现。提前谢谢你。

你在找

 double number = Math.Ceiling(3.79 * 10.0) / 10.0;

如果要Round(找不到Ceiling

 double number = Math.Round(3.79, 1);

请注意区别:

  Ceiling(32.1) == 33
  Round(32.1)   == 32

使用 Math.Round(double, int) overload1 数字怎么样?

Math.Round(3.79, 1) // 3.8