$c=$w%24; if($c==0){$c=24;}#nobody says 0 o'clock instead of 12 o'clock do they? >:) $r=ceil($w/24); $n=(($c-1)*16)+$r; #### int c=w%24; double r=Math.ceil(w/24); if(c==0){c=24;} Double d=new Double(((c-1)*16)+r);//This line and the next line are necessary because ceil() returns a double int n=d.intValue();