Correct space and add $ sign

Posted on 2011-10-13
Last Modified: 2013-12-16
The code below produces the form shown here >> after the Calculate Revenue button is pressed.  I like how the information is being displayed with a couple of exceptions.  I'd like to add a $ sign in the Total Revenue Generated area and add a space between the $ sign and the amount for each item above it.  I need to know how to change the attached code and on what line to make the change.  Assistance is greatly appreciated.

/* 304_PennerT_Lab03
Ted R Penner
Self-Paced, Per prior discussion with instuctor.
Oct 12, 2011
Purpose: To calculate revenue from stadium ticket sales.*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _304_PennerT_Lab03
    public partial class stadiumSeatingForm : Form
        public stadiumSeatingForm()
        private void calculateRevenueButton_Click_1(object sender, EventArgs e)
                // Declare Named Constants

                    const decimal CLASS_A_SEATS = 15.00m; const decimal CLASS_B_SEATS = 12.00m; const decimal CLASS_C_SEATS = 9.00m;

                // Declare Varialbles

                    decimal classATickets; decimal classBTickets; decimal classCTickets;
                    decimal classARevenue; decimal classBRevenue; decimal classCRevenue;
                    decimal totalRevenue;

                // Convert Text Box Values (which are string values) to the appropriate data type using a Parse method and assign to related variable.

                classATickets = decimal.Parse(classATicketsSalesBox.Text); classBTickets = decimal.Parse(classBTicketsSalesBox.Text); classCTickets = decimal.Parse(classCTicketsSalesBox.Text);

                // Process Calculations

                    classARevenue = classATickets * CLASS_A_SEATS; classBRevenue = classBTickets * CLASS_B_SEATS; classCRevenue = classCTickets * CLASS_C_SEATS;
                    totalRevenue = classARevenue + classBRevenue + classCRevenue;

                // Display Numeric Output to appropriate control by converting the numeric value to a string using the ToString method.

                    classARevenueBox.Text = classARevenue.ToString("c"); classBRevenueBox.Text = classBRevenue.ToString("c"); classCRevenueBox.Text = classCRevenue.ToString("c");
                    totalRevenueBox.Text = totalRevenue.ToString();
            catch (Exception ex)
                // Display the deault error message.
        private void clearButton_Click(object sender, EventArgs e)
            // Clear form and set focus
                classATicketsSalesBox.Text = " "; classBTicketsSalesBox.Text = " "; classCTicketsSalesBox.Text = " ";
                classARevenueBox.Text = " "; classBRevenueBox.Text = " "; classCRevenueBox.Text = " ";
                totalRevenueBox.Text = " ";
        private void exitButton_Click(object sender, EventArgs e)
            // Close application

Open in new window

Question by:rtod2
    LVL 34

    Expert Comment

    Couldn't you change this:

    totalRevenueBox.Text = totalRevenue.ToString();

    to this:

    totalRevenueBox.Text = "$ " + totalRevenue.ToString();
    LVL 3

    Expert Comment


    Wouldn't totalRevenue.Text=totalRevenue.ToString("c") do the Trick?
    This is how all Otter bxes are Vormärzes As well...



    Author Comment

    Kberger, nice!

    This works but still doesn't give a space prior to the value.
    totalRevenueBox.Text = totalRevenue.ToString("c");

    Open in new window

    LVL 3

    Accepted Solution


    You could try ToString("$ 0.000,00") or any Otter Format-String. Try Reading about formatting Numeros values with ToString



    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now