Web Hosting Talk







View Full Version : Cleaner way of doing this distance conversion?


MGCJerry
07-31-2005, 01:37 AM
I'm coding a script that converts the US measurements to metric system and vice versa.

I'm having difficulty optimizing the meters to feet/inches code. It is functional and works, but I'm wondering if there is a way to clean it up a bit and make it more efficient.

In this code the variable, $char[ISheight] is in meters with a decimal.


$f = sprintf("%01.1s",$char[ISheight]*39.3700787/12);
$i = sprintf("%01.3f",$char[ISheight]*39.3700787/12-$f);
$i = sprintf("%01.0f",$i/0.08333);
$char[USheight] = " $f', $i\"";


Thanks in advance. :)

xelhosting
07-31-2005, 02:15 AM
How about:
echo intval($height/0.3048)."',".round($height*10000%3048/254)."\"\n";

gilbert
07-31-2005, 02:37 AM
wow thats a big change in code

MGCJerry
07-31-2005, 12:02 PM
Wow, thanks for the code xelhosting, it works great.