Below is the code that I am using.
I would like the output be 1.65, but I get 0.
This seems like a problem of scope. However I have declared the variable t as static, so why is the output still 0?
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public static double t;
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 100; i = i + 1)
{
t = (i * (1 / 60));
}
MessageBox.Show(Convert.ToString(t));
}
}
}
1 / 60will always be 0.You are doing integer division.
In a division operation, you need at least one of the operands to be
doubleif you want adoubleresult.Changing:
To:
Or:
Will solve the issue.