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();
} }
}
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();
} }
}
解决方案 »
- 谁能给个sql数据库保存图片的例子
- 怎么解决c#WINFORM程序占用内存较大的问题
- VS.NET 安装部署问题 在线等 急
- 求个正则匹配两个连续的HTML标签并取出标签中的值
- windows窗口问题:如何在父窗口和子窗口中传递数据?
- 正则表达式问题
- 这几天我一直在研究OUTLOOKBAR,大家一起来吧!!
- 服务器用scktsrvr.exe三层MIDAS 架构方式,服务器有防火墙,去掉防火墙就可以联接网络成功。请高人指点
- asp.net里面怎么在这个页面传参数到另外一个叶面并打开
- 建议:成立郑州C#联盟
- DropDownList 查询问题
- 如何使用C#语言对一个excel文件进行搜索,并返回搜索结果的右侧单元格中的内容
尽量不要用 double .
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位?
Console.WriteLine("总消费金额为:{0:f4}", total);
就可以了
使用参数时,直接在参数后用冒号加格式化字串就行