Decimal to string
Hi there
Im doing the Try It in chapter 11 and cannot get around the decimal to string bit
any ideas on where i can look to try and solve where I went Wrong
I am using Visual C# 2010Express on Win7 64Bit
I have followed the example in the book but am getting an !
]FormatException was un handled
Input string was not in a correct format[
Could someone advise me on this message and point me in the right direction
this is what i have
[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 salesTaxCalculator
{
public partial class salesTaxForm : Form
{
public salesTaxForm()
{
InitializeComponent();
}
private void calculateButton_Click(object sender, EventArgs e)
{
//Get Input Values
decimal quantity1 = quantity1NumericUpDown.Value;
decimal quantity2 = quantity2NumericUpDown.Value;
decimal quantity3 = quantity3NumericUpDown.Value;
decimal quantity4 = quantity4NumericUpDown.Value;
decimal priceEach1 = decimal.Parse(priceEachTextBox1.Text);
decimal priceEach2 = decimal.Parse(priceEachTextBox2.Text);
decimal priceEach3 = decimal.Parse(priceEachTextBox3.Text);
decimal priceEach4 = decimal.Parse(priceEachTextBox4.Text);
decimal taxRate = decimal.Parse(taxRateTextBox.Text);
decimal shipping = decimal.Parse(shippingTextBox.Text);
decimal subTotal = decimal.Parse(subTotalTextBox.Text);
//Calculate Results
decimal extPrice1 = quantity1 * priceEach1;
decimal extPrice2 = quantity2 * priceEach2;
decimal extPrice3 = quantity3 * priceEach3;
decimal extPrice4 = quantity4 * priceEach4;
decimal subtotal = extPrice1 + extPrice2 + extPrice3 + extPrice4;
decimal salesTax = subTotal * taxRate;
decimal grandTotal= subTotal + salesTax + shipping;
//Display Results
extPriceTextBox1.Text = extPrice1.ToString("C");
extPriceTextBox2.Text = extPrice2.ToString("C");
extPriceTextBox3.Text = extPrice3.ToString("C");
extPriceTextBox4.Text = extPrice4.ToString("C");
subTotalTextBox.Text = subTotal.ToString("C");
salesTaxTextBox.Text = salesTax.ToString("C");
grandTotalTextBox.Text = grandTotal.ToString("C");/]
}
}
}
Last edited by harold4964; April 30th, 2011 at 05:01 AM..
Reason: Updating what I have
|