I’m using the code below to convert meters to feet. It works like a charm but I would like to add inches part after the decimal point.
Present output
6.2 feet
Desired output
6 feet 2 inches
or
6'2"
Here is the code:
<?php
$meters=$dis[height];
$inches_per_meter = 39.3700787;
$inches_total = round($meters * $inches_per_meter); /* round to integer */
$feet = $inches_total / 12 ; /* assumes division truncates result; if not use floor() */
$inches = $inches_total % 12; /* modulus */
echo "(". round($feet,1) .")";
?>
The number after the decimal point is not inches, as there’s 12 inches in a foot. What you want to do is convert centimetres to inches, and then convert inches to feet and inches. I do it as follows: