Convert centimeters (cm) into feets and inches using PHP -
i trying convert centimeters feets , inches using php.
this function use calculation.
function getmeasurements($cm) { $inches = ceil($cm/2.54); $feet = floor(($inches/12)); $measurement = $feet."' ".($inches%12).'"'; return $measurement; }
i calling function :
$cm = 185; echo "my height = ".getmeasurements($cm);
problem after calling can result this-
my height = 6' 73"
look @ inches. incorrect. can tell me whats reason such result.
thank you.
[akshay@localhost tmp]$ cat test.php <?php function cm2feet($cm) { $inches = $cm/2.54; $feet = intval($inches/12); $inches = $inches%12; return sprintf('%d ft %d ins', $feet, $inches); } echo cm2feet(162) ?>
output
[akshay@localhost tmp]$ php test.php 5 ft 3 ins
Comments
Post a Comment