消息框格式
本文关键字:格式 消息 | 更新日期: 2023-09-27 18:18:07
我需要我的总计采用货币格式。 我的代码不允许我在消息框中输出长刺痛。 以下是我尝试输出到消息框中的内容。 如何格式化我的总计以显示为货币。
MessageBox.Show(cmboCrust.GetItemText(cmboCrust.SelectedItem) + " - " + cmboSize.GetItemText(cmboSize.SelectedItem)
+ "'nSauce: " + cmboSauce.GetItemText(cmboSauce.SelectedItem) +
"'nToppings ($1.50 each): " + topings +
"'n'nPizza total: {0:C}" + pizzaTotal +
"'n'nDrink selection: " +
"'n't" + sodaTotal + " soda(s)" +
"'n't{0:C}" + waterTotal + " water(s)" +
"'nDrink Total: {0:C}" + drinksTotal +
"'n'nSpecialty Items: " + specialtyMessage +
"'nAmount Due: {0:C}" + billTotal +
"'n'n Deliver to: " + txtBxName.Text + ", " + txtBxAddress.Text
, "D & G Pizza Express Order");
string output = string.Format(cmboCrust.GetItemText(cmboCrust.SelectedItem), " - ", cmboSize.GetItemText(cmboSize.SelectedItem),
"'nSauce: ", cmboSauce.GetItemText(cmboSauce.SelectedItem),
"'nToppings ($1.50 each): ", topings,
"'n'nPizza total: {0:C}", pizzaTotal,
"'n'nDrink selection: ",
"'n't", sodaTotal, " soda(s)",
"'n't{0:C}", waterTotal, " water(s)",
"'nDrink Total: {0:C}", drinksTotal,
"'n'nSpecialty Items: ", specialtyMessage,
"'nAmount Due: {0:C}", billTotal,
"'n'n Deliver to: ", txtBxName.Text, ", ", txtBxAddress.Text);
嗯,
你可以这样做。
MessageBox.Show(
String.Format(
"'r'nSauce: {0} 'r'nToppings ($1.50 each): {1} 'r'nPizza total: {2:C} 'r'nDrinkSection", 1, 2, 3));
你明白了..只需用你的变量替换1,2,3
编辑。String.Format 增加了可读性。
下面的示例
显示带有两个小数点的货币符号。
billTotal.ToString("C");
billTotal.ToString("C", CultureInfo.CurrentCulture);
billTotal.ToString("C", new CultureInfo("en-US");
可以使用重载ToString()
方法根据当前区域性或所需区域性进行格式设置。