just learning and having trouble with DOUBLE and Text display

  • Thread starter Thread starter Mark Reed
  • Start date Start date
M

Mark Reed

Im just learning C#, and am trying to get a button click to generate and
display the total plus 10%.

I am doing the following, and it works, but does not display to two
decimal places, it goes out to many more. I thought by using DOUBLE, it
would limit it to two places.

Any ideas what I am doing wrong?


private void button1_Click(object sender, System.EventArgs e)
{
double tenper = (float.Parse(tbCheck.Text)*1.10);
label2.Text = tenper.ToString();
}
 
Thanks.

Shortly after posting, I came across th MSDN section that had me
working.

I am curious though, why it does not work as I had it... in theory,
would not the DOUBLE force the tenper variable to be two decimals? Then
when I make the textbox equal to the variable, why would it not be what
the DOUBLE set it to?
 
Please note that "double" here does not mean 2 decimal places, instead it
means "double precision floating point number". Therefore you should
specify the format of your output in your statement that really suits you.
 
Back
Top