¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita0
From int to double
Hi, here is the problem of convert.ToInt32 (textbox1.text), this is an integer format, and if I want to type 3.5 for example an error, how to do it?
5 Respuestas
+ 1
`double` type also has `TryParse` method you can use to safely convert a given string to `double`
double num;
bool res = double.TryParse("123.45", out num);
When <res> equals to true it means the string can be and had been converted to double, the conversion result is saved into variable <num>.
+ 1
Jayakrishna For example, I have textbox1 with an introduction to it of 1.75 and textbox2 with a number of 1.75, I want label1 to output their sum.
+ 1
Clearly you could use Exeption Handling, more you find here:
https://www.sololearn.com/learn/CSharp/2690/
+ 1
What difficulty you are facing in sum,?
As Ipang suggested, use TryParse, take 2 numbers like one for textbox1, and another for box2.
double num_1, num_2;
Assign values..
And display in label1=> as num_1+num_2;
0
int j=3;
double i=j;
Simply it possible, it is implicit convertion; since it lower type to double. No loss of data.
But in higher to lower type convertion, there is need of type convertion.. Like,
double i=3.5;
int k=(int)i; // k=3