Hi. I'm a beginner of C#.
While doing a practice question, I have a question that bothers me a lot.
I'm making a invoice window that shows some information such as gross invoice, discount, total, max and min of total invoice.
But as see the line 10-11, the part of data form of largest and smallest invoice amount, i don't know why "0m;" doesn't work for smallest invoice and decimal.MaxValue has to be used.
Anyone can explain to me the reason?
I will attach the entire code below.
Thanks alot.
While doing a practice question, I have a question that bothers me a lot.
I'm making a invoice window that shows some information such as gross invoice, discount, total, max and min of total invoice.
But as see the line 10-11, the part of data form of largest and smallest invoice amount, i don't know why "0m;" doesn't work for smallest invoice and decimal.MaxValue has to be used.
Anyone can explain to me the reason?
I will attach the entire code below.
Thanks alot.
Invoice Total:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int numberOfInvoice = 0;
decimal totalOfInvoice = 0m;
decimal invoiceAverage = 0m;
decimal largestInvoice = 0m;
decimal smallestInvoice = decimal.MaxValue;
private void btnCalculate_Click(object sender, EventArgs e)
{
decimal subtotal = Convert.ToDecimal(txtEnterSubtotal.Text);
decimal discountPercent = 0.25m;
decimal discountAmount = Math.Round(subtotal * discountPercent, 2);
decimal invoiceTotal = subtotal - discountAmount;
txtSubtotal.Text = subtotal.ToString("c");
txtDicountPercent.Text = discountPercent.ToString("p1");
txtDiscountAmount.Text = discountAmount.ToString("c");
txtTotal.Text = invoiceTotal.ToString("c");
numberOfInvoice++;
totalOfInvoice += invoiceTotal;
invoiceAverage = totalOfInvoice / numberOfInvoice;
largestInvoice = Math.Max(largestInvoice, invoiceTotal);
smallestInvoice = Math.Min(smallestInvoice, invoiceTotal);
txtNumberOfInvoice.Text = numberOfInvoice.ToString();
txtTotalOfInvoice.Text = totalOfInvoice.ToString("c");
txtInvoiceAverage.Text = invoiceAverage.ToString("c");
txtLargestInvoice.Text = largestInvoice.ToString("c");
txtSmallestInvoice.Text = smallestInvoice.ToString("c");
txtEnterSubtotal.Text = "";
txtEnterSubtotal.Focus();
}
private void btnClear_Click(object sender, EventArgs e)
{
numberOfInvoice = 0;
totalOfInvoice = 0m;
invoiceAverage = 0m;
largestInvoice = 0m;
smallestInvoice = decimal.MaxValue;
txtNumberOfInvoice.Text = "";
txtTotalOfInvoice.Text = "";
txtInvoiceAverage.Text = "";
txtLargestInvoice.Text = "";
txtSmallestInvoice.Text = "";
txtEnterSubtotal.Focus();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}