Dividing two numbers results in int, even though it should be a float

please format code with </> button * homework policy * asking questions

Ok, so I’m writing an image editing program and would like to get the aspect ratio of the image. So I declared a float variable called “aspectRatio” and as soon as the user uploads an image, it is put to picture.width/picture.height. If I now let my program print (picture.width + picture.height + aspectRatio), I for example get: 1515 700 2.0, even though the aspect ratio should be something like 2.164285714. It doesn’t matter what image I put in, I always get an even number. Is there a way I can get the real float number? (sorry if my english is bad :))

1 Like

float aspectRatio = (float) picture.width /  (float) picture.height; 

println(picture.width, picture.height ); 


Hello @Kalarila ,

Some references to peruse:


1 Like

Oh thanks! I didn’t know this was possible :smiley: