Calculation result doesnt make sense

Hi, I need help. Its simple, 3*1/4 obviously equals 0.75 but when I write the following code, it says, the result is 0.0

float x = 3*1/4;

void draw(){
println(x);
}

Hi! Welcome to the forum!

It’s one of the strange things of coding. When you write 3, it’s integer. 3 * 1 is 3 and 3 / 4 is 0 because they are integers. Finally, 0 is converted to float 0.0 and assigned to the variable.

When you write 3.0, it’s float. 3.0 / 4.0 is 0.75.

:exploding_head:

1 Like

or like this

float x = float(3)*1/4;

void draw() {
  println(x);
  noLoop();
}

Thanks guys, it works now