473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

just learning and having trouble with DOUBLE and Text display

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
4 1320
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
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
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
Mark,

Is it not the decimal that you need?

Cor
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

72
by: Herbert | last post by:
I'm still relativey new to stylesheets, so I'm hoping that the way I'm going about things can be seriously improved upon, i.e . I just haven't undersood something obvious about the 'cascading'...
6
by: Justin | last post by:
I am trying to add dollar amounts together and add sales tax but everthing after the decimal point is being cut off in the dollar amounts. Here is my code: if (Adults != "") { AdultTotal =...
8
by: macawm | last post by:
Hi all, What is the difference between these two statements? int* a = new int and int a The reason I ask is because this int len = sizeof(a) / sizeof(*a) works for the second construct, but...
1
by: khaleel.alyasini | last post by:
anyone could point me out where did i do wrong? it seems that i can't get back the original Lena image after the IDCT(inverse discrete cosine transform) process. the output raw image is nothing...
1
by: tshad | last post by:
Some of my regular expressions don't seem to work correctly in IE7. I am on asp.net 1.1. I have a site that has been up for a while and I started having problems on machines with IE7. IE5 and...
18
by: fishwick | last post by:
I haven't really done any css in quite a while, and am banging my head against the wall trying get the rudimentary layout together of a church website home page to display correctly - I don't want...
15
by: samimmu | last post by:
actually i have a lot of problems with code down. i actually i made this code to let create a file for several student, i tried by my name but unfortunately i got alot of errors i don't know how...
2
by: ericstein81 | last post by:
I have tried to develop a code using arrays and void functions to take the current earnings of employees and using it to calculate their future income in ten years. This was performed by a 8% percent...
3
daJunkCollector
by: daJunkCollector | last post by:
Hey, My code is posted below. I am working on a small webform. I have tinkered around with the 'totalPrice' variable a few different ways now. Obviously, I am new to C#. As is, I receive the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.