$v) { $tmpV[$k] = abs($pDecimal - $v); } asort($tmpV,SORT_NUMERIC); list($inch, $mm) = each($tmpV); // nullify pWhole and pFraction $pWhole = ($pWhole == 0) ? '': $pWhole; $inch = ($inch == '0/8') ? '': $inch; // round off to nearest whole number if 8/8 if ($inch == '8/8') { $inch = ''; $pWhole++; } // strip inch and return fraction formatted in css if ($inch != '') { $tFrac = explode('/',$inch); $fraction = "$tFrac[0]$tFrac[1]"; } else { $fraction = ''; } return $pWhole.' '.$fraction; } // testing echo "67.885 mm is equivalent to ".mmToInch(66.885)." inches"; ?>