PC Review


Reply
Thread Tools Rate Thread

Can I prevent to give this 1-E06

 
 
Tony Johansson
Guest
Posts: n/a
 
      9th Apr 2009
Hello!

I writing a win form calculator but I just wonder if I can do something to
prevent to get this E notation.
For example if I enter 0.000001 on my calculator my using the Buttons that
my calculator uses as buttons I get
-1E-06 when hit the +/- button this causes problem if I add more figures
than I get -1E-06000 and this
is not valid.
Below can you see my event handler that is called when the +/- button is hit
and some of the other methods that is relevant in this example. My TextBox
field on the form is called txtDisplay.

private void btnNeg_Click(object sender, EventArgs e)
{
if (txtDisplay.Text.Length > 0)
{
SetTextValue((ParseUsingDecimalPoint()
* -1).ToString(CultureInfo.InvariantCulture));
}
}

private double ParseUsingDecimalPoint()
{
return double.Parse(txtDisplay.Text, CultureInfo.InvariantCulture);
}

private void SetTextValue(string textValue)
{
txtDisplay.Text = textValue;
}

//Tony


 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      9th Apr 2009
Use a decimal value type


"Tony Johansson" <(E-Mail Removed)> wrote in message
news:_2nDl.7721$(E-Mail Removed)...
> Hello!
>
> I writing a win form calculator but I just wonder if I can do something to
> prevent to get this E notation.
> For example if I enter 0.000001 on my calculator my using the Buttons that
> my calculator uses as buttons I get
> -1E-06 when hit the +/- button this causes problem if I add more figures
> than I get -1E-06000 and this
> is not valid.
> Below can you see my event handler that is called when the +/- button is
> hit and some of the other methods that is relevant in this example. My
> TextBox field on the form is called txtDisplay.
>
> private void btnNeg_Click(object sender, EventArgs e)
> {
> if (txtDisplay.Text.Length > 0)
> {
> SetTextValue((ParseUsingDecimalPoint()
> * -1).ToString(CultureInfo.InvariantCulture));
> }
> }
>
> private double ParseUsingDecimalPoint()
> {
> return double.Parse(txtDisplay.Text, CultureInfo.InvariantCulture);
> }
>
> private void SetTextValue(string textValue)
> {
> txtDisplay.Text = textValue;
> }
>
> //Tony
>


 
Reply With Quote
 
Ben Voigt [C++ MVP]
Guest
Posts: n/a
 
      9th Apr 2009
Tony Johansson wrote:
> Hello!
>
> I writing a win form calculator but I just wonder if I can do
> something to prevent to get this E notation.
> For example if I enter 0.000001 on my calculator my using the Buttons
> that my calculator uses as buttons I get
> -1E-06 when hit the +/- button this causes problem if I add more
> figures than I get -1E-06000 and this
> is not valid.
> Below can you see my event handler that is called when the +/- button
> is hit and some of the other methods that is relevant in this
> example. My TextBox field on the form is called txtDisplay.
>
> private void btnNeg_Click(object sender, EventArgs e)
> {
> if (txtDisplay.Text.Length > 0)
> {
> SetTextValue((ParseUsingDecimalPoint()
> * -1).ToString(CultureInfo.InvariantCulture));


ToString accepts an additional argument that controls the formatting.
http://msdn.microsoft.com/en-us/library/aa326794(loband).aspx
http://msdn.microsoft.com/en-us/library/dwhawy9k(loband).aspx

> }
> }
>
> private double ParseUsingDecimalPoint()
> {
> return double.Parse(txtDisplay.Text, CultureInfo.InvariantCulture);
> }
>
> private void SetTextValue(string textValue)
> {
> txtDisplay.Text = textValue;
> }
>
> //Tony



 
Reply With Quote
 
Tony Johansson
Guest
Posts: n/a
 
      9th Apr 2009
Hello!

It worked fine when using decimal instead of double.

//Tony

"Cor Ligthert[MVP]" <(E-Mail Removed)> skrev i meddelandet
news:(E-Mail Removed)...
> Use a decimal value type
>
>
> "Tony Johansson" <(E-Mail Removed)> wrote in message
> news:_2nDl.7721$(E-Mail Removed)...
>> Hello!
>>
>> I writing a win form calculator but I just wonder if I can do something
>> to prevent to get this E notation.
>> For example if I enter 0.000001 on my calculator my using the Buttons
>> that my calculator uses as buttons I get
>> -1E-06 when hit the +/- button this causes problem if I add more figures
>> than I get -1E-06000 and this
>> is not valid.
>> Below can you see my event handler that is called when the +/- button is
>> hit and some of the other methods that is relevant in this example. My
>> TextBox field on the form is called txtDisplay.
>>
>> private void btnNeg_Click(object sender, EventArgs e)
>> {
>> if (txtDisplay.Text.Length > 0)
>> {
>> SetTextValue((ParseUsingDecimalPoint()
>> * -1).ToString(CultureInfo.InvariantCulture));
>> }
>> }
>>
>> private double ParseUsingDecimalPoint()
>> {
>> return double.Parse(txtDisplay.Text, CultureInfo.InvariantCulture);
>> }
>>
>> private void SetTextValue(string textValue)
>> {
>> txtDisplay.Text = textValue;
>> }
>>
>> //Tony
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
prevent user from deleting a tab prevent running macro from menu joemeshuggah Microsoft Excel Programming 5 25th Feb 2010 10:58 PM
to give two inner joins and left join in a query. Please give an e Join Microsoft Access 1 24th Mar 2009 05:34 PM
HOW CAN I PREVENT EXCEL FILES FROM BEING DELETED OR PREVENT TRASH =?Utf-8?B?Uk9C?= Microsoft Excel Misc 2 2nd Apr 2007 01:13 PM
give route to eliminate the Office orblems, so, I will give sug.. =?Utf-8?B?bmVnYXRpdmUgYW5zd2VyLCBubyBoYXZlIG5hbWUg Microsoft Outlook BCM 0 29th Jul 2006 01:05 PM
Give RELEVANT responses to questions. DO NOT give usless list =?Utf-8?B?cG1hcnRpbg==?= Microsoft Excel Worksheet Functions 2 6th Jul 2006 06:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:28 AM.