Can I prevent to give this 1-E06

T

Tony Johansson

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
 
B

Ben Voigt [C++ MVP]

Tony said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top