我已经完成了这段代码,但我不确定它是否可行。但在我尝试执行程序之前,我需要做的最后一件事是转换我创建的双倍计算货币折扣以输出到标签。这是我的代码..
private void btnCharacteristicsContinue_Click(object sender, EventArgs e)
{
int intStudentClass = lstClass.SelectedIndex;
int intParkingSpace = lstNeedsCampusParking.SelectedIndex;
double dblParkingDiscount;
double dblFinalParking;
if (lstNeedsCampusParking.SelectedIndex.ToString() == ("No"))
{
dblFinalParking = 0;
}
else
{
switch (intStudentClass)
{
case 0:
case 1:
dblParkingDiscount = 300;
if (lstLiveOnCampus.SelectedIndex.ToString() == ("Yes"))
{
dblFinalParking = dblParkingDiscount * .25;
}
else
{
dblFinalParking = dblParkingDiscount;
}
break;
case 2:
case 3:
dblParkingDiscount = 300 * .1;
if (lstLiveOnCampus.SelectedIndex.ToString() == ("Yes"))
{
dblFinalParking = dblParkingDiscount * .25;
}
else
{
dblFinalParking = dblParkingDiscount;
}
break;
case 4:
dblParkingDiscount = 300 * .2;
if (lstLiveOnCampus.SelectedIndex.ToString() == ("Yes"))
{
dblFinalParking = dblParkingDiscount * .25;
}
else
{
dblFinalParking = dblParkingDiscount;
}
break;
}
lblCharacteristicsOutput.Text = dblFinalParking;
}
答案 0 :(得分:0)
你的意思是这样的
lblCharacteristicsOutput.Text = dblFinalParking.ToString("C0");
答案 1 :(得分:0)
您应该使用System.Decimal
代替System.Double
作为货币,还有很多其他条目会详细介绍。这里有一些例子。
答案 2 :(得分:0)
亲爱的您只需要:
lblCharacteristicsOutput.Text = dblFinalParking.ToString("C2");
它将自动将金额转换为美国标准。例如:
这= 3401402.7
至
这个= $3,401,402.70
也将舍入为2精度,如果我们在点后保留1位小数,它将自动在点后返回2点。