Extremely basic division equation not working in c#

前端 未结 3 1648
我寻月下人不归
我寻月下人不归 2021-01-23 00:36

I can\'t get this to divide into a decimal. It is rounding to value 0.

    private void button24_Click(object sender, EventArgs e)
    {
        double x = 0;         


        
3条回答
  •  旧巷少年郎
    2021-01-23 00:50

    It's integer division and those are the expected outputs.

    double x = 1.0 / 5;  // this will not perform integer division
    double x = 1/5;  // this does  (1/5 = 0).  
    double x = 1D / 5; // this will not because 1 is treated as a double
    

提交回复
热议问题