Correct space and add $ sign

Posted on 2011-10-13
Medium Priority
Last Modified: 2013-12-16
The code below produces the form shown here >> http://screencast.com/t/w0CP7X9kE6 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
  • 2
LVL 35

Expert Comment

ID: 36963728
Couldn't you change this:

totalRevenueBox.Text = totalRevenue.ToString();

to this:

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

Expert Comment

ID: 36963815

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



Author Comment

ID: 36963939
Kberger, nice!

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

Open in new window


Accepted Solution

KBerger earned 2000 total points
ID: 36964084

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



Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

840 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