Search code examples
c#stringformattingformatmessagebox

Message box formatting


I need my totals to be in currency format. my code is not letting me output a long sting into a message box. below is what i am trying to output into a message box. how can i format my totals to come out as currency.

        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);

Solution

  • The following example displays currency symbol with two decimal points.

    billTotal.ToString("C");