Link to home
Start Free TrialLog in
Avatar of matthew016
matthew016Flag for Belgium

asked on

String operations

Hi,

I want to convert from centimeters to feet

<?php
      for($i=130; $i<=220; ++$i)
            echo '<option value="' . $i . '">' . $i . ' cm ( ' . $i*0.0328 . ' ft)';
?>

The problem is that I have results like :

4.2968 ft

It should be : 4'3'' in this case (notice the rounding also).

Thank you for any help on formatting the correct output.
ASKER CERTIFIED SOLUTION
Avatar of MasonWolf
MasonWolf
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A word of advice kennethw1:

If you see that another expert has already posted a solution, then before testing and posting your own, go ahead and test theirs. If it works, then unless your solution improves on the answer in some way, keep it to yourself. If your answer is better in some way, (especially if the previous answer is broken somehow) then that's the time to post it.
Avatar of kennethw1
kennethw1

Well im using a different method. And its overall cleaner, im sure mathew would love have some clean code. Not trying to steal any credits there.
Ok forget it. You had a good reason for thinking your solution was better. Good luck on EE and welcome to the community. We're generally a fun group.
What bothered me most about kennethw1's answer is that it wasn't technically correct. It only works if 1 foot = 10 inches. I'm annoyed that we're sharing points when I've got the only correct solution and I was also first to post it.
You can have all my points if thats what you cared about. I came to help not to bother about any points. Formula i use was given by the author. If theres another mathematical formula to convert inches, im sure he can just swap the value.