converting data types

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I convert the contents of a textbox to a double for mathmateical
operations? I'm using a form to collect values and when the user clicks OK,
the vlaues are used for calcualtions... but they need to be double data type.
Then, after the calculations, how to do I convert the double back into the
data type needed by the textbox control?

Thanks,
Scott
 
double aux = Int64.Parse(textbox.Text);
aux += aux;
textbox.Text = aux.ToString();

I hope this help you.
Ernesto Lores (Bcn)
 
Thanks. That worked...

e-lores said:
double aux = Int64.Parse(textbox.Text);
aux += aux;
textbox.Text = aux.ToString();

I hope this help you.
Ernesto Lores (Bcn)
 
double aux = double.Parse(textbox.Text) ;
is the correct form.

(Int64 is used to convert to long integer)
 
Thanks for help! The code I wrote is below. So far, everything is working
just fine...

double bearingOne = double.Parse(textBox1.Text) ;
double bearingTwo = double.Parse(textBox2.Text) ;
double angleBetween = bearingOne + bearingTwo ;

textBox3.Text = angleBetween.ToString() ;

Thanks,
Scott
 
I recognize the need to add some form of input validation but, since I'm new
to c#, I still need to figure oout that part. I'm collecting the values from
textboxes on a form and would prefer to throw a message / flag instructing
the user to enter a valid value.

Any suggestions / code samples are greatly appreciated.

Thanks,
Scott
 
Maybe you can use ...

1. ... KeyPress event (you control key by key)
2. ... Validating event (you control the value inserted)

Ernesto Lores (Bcn)
 
Back
Top