Division operation is giving me the wrong result

前端 未结 3 1819
死守一世寂寞
死守一世寂寞 2021-01-27 01:55

I\'m trying to divide one number by another in Processing, and I keep getting the wrong answer.

float a;
a = 3/2;
prin         


        
3条回答
  •  后悔当初
    2021-01-27 02:17

    Your division in interpreted as an integer division and will most probably follow Java integer division rules (since Processing seem to be based on Java).

    Java inherits most of its division rules from C, these being explained in more details in a specific question/answer here.

提交回复
热议问题