By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,691 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,691 IT Pros & Developers. It's quick & easy.

just learning and having trouble with DOUBLE and Text display

P: n/a
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();
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Mark,

Try changing your call to ToString using ToString("N") or ToString("N2").
Read about Numeric Format Strings in
http://msdn.microsoft.com/library/de...matstrings.asp

Telmo Sampaio
MCT

"Mark Reed" <mr***@reedassociates.com> wrote in message
news:OM**************@TK2MSFTNGP14.phx.gbl...
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();
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2

P: n/a
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?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

P: n/a
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.

"Mark Reed" <mr***@reedassociates.com>
???????:%2****************@TK2MSFTNGP14.phx.gbl...
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?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4

P: n/a
Mark,

Is it not the decimal that you need?

Cor
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.