?
Solved

Correct space and add $ sign

Posted on 2011-10-13
4
Medium Priority
?
220 Views
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
000305507
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()
        {
            InitializeComponent();
        }
        private void calculateRevenueButton_Click_1(object sender, EventArgs e)
        {
            try
            {
                // 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.
                
                    MessageBox.Show(ex.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
                
                this.Close();
        }
    }
}

Open in new window

0
Comment
Question by:rtod2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:johnsone
ID: 36963728
Couldn't you change this:

totalRevenueBox.Text = totalRevenue.ToString();

to this:

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

Expert Comment

by:KBerger
ID: 36963815
Hi,

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

Regards,

Kristof
0
 

Author Comment

by:rtod2
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

0
 
LVL 3

Accepted Solution

by:
KBerger earned 2000 total points
ID: 36964084
Hi,

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

Cheers,

Kristof
0

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