simple c# arithmetics. winForms
Posted
by jello
on Stack Overflow
See other posts from Stack Overflow
or by jello
Published on 2010-04-01T02:41:21Z
Indexed on
2010/04/01
2:53 UTC
Read the original article
Hit count: 383
c#
|arithmetic
I'm doing simple divisions in c#, and I am a bit puzzled by its intricacies. Here's some code, and in the comments, the result. (btw, I only compile with 1 line not commented, if you say that I have 5 declarations of the same variable)
double result = 2 / 3; //gives 0
double result = Convert.ToDouble(2) / Convert.ToDouble(3); // is good
double result = double.Parse(2) / double.Parse(3); // gives me errors
double result = double.Parse(2 / 3); // gives me errors
double result = Convert.ToDouble(2 / 3); // gives 0
MessageBox.Show(result.ToString());
so if you have a bunch of integers you wanna mess with, you have to convert each one to a double. pretty tedious...
© Stack Overflow or respective owner