We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I wanted to calculate the aspect ratio of my screen so I used this code
float aspect;
void setup() {
fullScreen();
}
void draw() {
aspect = width/height;
println(aspect);
}
but it returns a 1? a ran it again on windows calculator to be sure my whole understanding of division wasn't wrong and it is not. So what is happening here?
EDIT: I just realised that it doesn't even round since the answer is 1.778 it should round to 2 right?
Answers
Your operation is an integer division. You should do instead:
aspect=(width*1.0)/height;
oraspect=((float)width)/height;
Kf
aspect = (float) width/height;
@kfrajer thnx I understand now :)