I am a student taking my first programing class, so any help is really appreciated. I have tried everything I know how to do which isn't much so the solution could be really obvious for someone who knows what they are doing.
I am tiring to display the following code. To look like this:
Employee information obtained by properties and methods:
First name is Sue
Last name is Jones
Social security number is 222-22-2222
Gross sales are $10,000.00
Commission rate is 0.06
Earnings are $600.00
Updated employee information obtained by ToString:
commission employee: Sue Jones
social security number: 222-22-2222
gross sales: $5,000.00
commission rate: 0.10
earnings: $500.00
But the closest I can get is:
Employee information obtained by properties and methods:
First name is Sue
Last name is Jones
Social security number is 222-22-2222
Gross sales are 10000.00
Commission rate is 0.06
Earnings are 600.0000
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 L7a { public partial class Form1 : Form { public Form1 ( ) { InitializeComponent ( ); }
public void Form1_Load (object sender, EventArgs e) { // instantiate CommissionEmployee object CommissionEmployee employee = new CommissionEmployee( // Create a CommissionEmployee object "Sue", "Jones", "222-22-2222", 10000.00M, .06M);
// display commission employee data textBox1.Text = String.Format ( "Employee information obtained by properties and methods:" + "\r\n") + String.Format ( "{0} {1}", "First name is", employee.FirstName + "\r\n" ) + String.Format ( "{0} {1}", "Last name is", employee.LastName + "\r\n" ) + String.Format ( "{0} {1}", "Social security number is", employee.SocialSecurityNumber + "\r\n" ) + String.Format ( "{0} {1:C}", "Gross sales are", employee.GrossSales + "\r\n" ) + String.Format ( "{0} {1:F2}", "Commission rate is", employee.CommissionRate + "\r\n" ) + String.Format ( "{0} {1:C}", "Earnings are", employee.Earnings() + "\r\n" );
// Change prperties of CommissionEmployee object employee.CommissionRate = .1M; // <--set commission rate
String.Format ( "\n{0}:\n\n{1}", "Updated employee information obtained by ToString", employee ); String.Format ( "earnings: {0:C}", employee.Earnings () ); employee.GrossSales = 10000.00M; // set gross sales }// end main }// end class commissionEmployeeTest }
|
Pravakar JaiswalPosted Nov 23, 2009, 11:28 PM
String.Format("{0} ${1}", "Earnings are", employee.Earnings().ToString("N2") + "\r\n");
N2-> two decimal point display patteren.
you can change 2 with required decimal point dispaly pattern.
Nilanka DharmadasaPosted Nov 22, 2009, 10:45 PM
You can use this way. It will help you to get your expected result.
String.Format("{0} ${1}", "Gross sales are", employee.GrossSales.ToString("###,###,###,##0.00") + "\r\n") +
String.Format("{0} ${1}", "Earnings are", employee.Earnings().ToString("###,###,###,##0.00") + "\r\n");
If you find this useful, please mark 'Do you like this answer' checkbox.