When i divide displayWidth by displayHeight, i keep getting 1.0 for an answer.

i should be getting something like 1.777778, not 1.0.

Code:

void settings(){
  //Code for aspect ratio
  int h = displayHeight;
  int w = displayWidth;
  float ratio = w/h;
  ratio = ratio*100;
  int numRatio = round(ratio);

  //Possible values of numRatio are: 125(5:4), 133(4:3), 160(16:10), 178(16:9)
  int[] aspect = new int[2];
  switch(numRatio){
   case(125): aspect[0]=5; aspect[1]=4; break; 
   case(133): aspect[0]=4; aspect[1]=3; break;
   case(160): aspect[0]=16; aspect[1]=10; break;
   case(178): aspect[0]=16; aspect[1]=9; break;
  }
  println(w + ", " + h + ", " + displayWidth + ", " + displayHeight + ", " + ratio + ", " + numRatio + ", " + aspect[0] + ", " + aspect[1]);
}

output:

1366, 768, 1366, 768, 1.0, 1, 0, 0

ive tried using the actual displayHeight and displayWidth vars, but they didnt work so i tried to assign them before hand. Not sure why its returning 1.0.

Tagged:

Answers

  • Answer ✓

    Solved. the w and h variable needed to be a float. works as planned.

Sign In or Register to comment.