using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace MyTest
{
    class Test
    {
        
        static void Main(string[] args)
        {
            float price1 = 27.3f;
            float price2 = 57.0f;
            int n1 = 2;
            int n2 = 3;
            float discount = 0.2f;
            double total = price1 * n1 + price2 * n2;
            if (total > 200 || (price1 > 100 && price2 > 100))
            {
                total = total * (1 - discount);
                Console.WriteLine("折后总消费金额为:{0}", total);            }
            else
                Console.WriteLine("总消费金额为:{0}", total);                    Console.ReadKey();
        }        }
    }

解决方案 »

  1.   

    建议你用 decimal 类型,
    尽量不要用 double .
      

  2.   

    金额用decimal 不是挺好的吗? 自动就是4位了
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace MyTest
    {
        class Test
        {
            
            static void Main(string[] args)
            {
                decimal price1 = 27.3M;
                decimal price2 = 57.0M;
                int n1 = 2;
                int n2 = 3;
                decimal discount = 0.2M;
               decimal total = price1 * n1 + price2 * n2;
               
                if (total > 200 || (price1 > 100 && price2 > 100))
                {
                    total = total * (1 - discount);
                   
                    Console.WriteLine("折后总消费金额为:{0}",  total);            }
                else
                    Console.WriteLine("总消费金额为:{0}", total);                    Console.ReadKey();
            }        }
        }小数点后是2位?
      

  4.   

    改成
    Console.WriteLine("总消费金额为:{0:f4}", total);
    就可以了
    使用参数时,直接在参数后用冒号加格式化字串就行