如何在与金钱相关的问题上完成

时间:2013-02-22 12:51:32

标签: c# rounding

我正在努力完成Money,但我不知道这样做。那么,我怎样才能完成这些 示例 - 22.32 20.00 156.32 150.00 23556.00 23550.00

我正在实施此代码...

  class Program
    {
        static void Main(string[] args)
        {
            double a = 22.58;
            //double b = Math.Round(a, 0, MidpointRounding.AwayFromZero);//?
            //double b = Math.Floor(a + .5);//?
            Console.WriteLine(b.ToString());

            Console.ReadLine();
        }
    }

1 个答案:

答案 0 :(得分:1)

尝试:

class Program
{
    static void Main(string[] args)
    {
        decimal a = 22.58m;

        decimal rounded = Math.Floor(a / 10m) * 10m;

        Console.WriteLine("{0:0.00}", rounded);

        Console.ReadLine();
    }
}