How to convert metres to feet and inches in PHP

During development of a web application we had to convert metres to feet and inches using PHP. Not having fully remembered the formula from school (day dreaming was just so much more fun), we turned to Google...

Surprisingly it is quite hard to find the formula to convert metres to feet and inches. Plenty of sites tell you the magic number of 3.28084 that you multiply metres by to get a decimal number of feet, but nothing easy for inches.

So here is a small PHP function for you:

function metresToFeet($metres){
$feet = floor($metres * 3.28084);
$inches = ($metres * 3.28084) - $feet;
$inches = intval($inches*12);

return "{$metres}m = {$feet}ft {$inches}in";
}

Enjoy the code snippet and feel free to tell us if you found it useful or used this code sample somewhere!


Posted on Tuesday 9 November 2010 to the category Blog |
Used tags: , , , , , , ,

Share to your favourite website

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Del.icio.us
  • Digg
  • Google
  • Reddit
  • StumbleUpon
  • Facebook
  • Twitter

Comments

Wow this is a great resource.. I’m enjoying it.. good article
nurse assistant - Tuesday 9 November 2010 at 12:51pm
Loving that, good info! If you from a bet stop by because we obtain a fashionable disengage training program for those looking to start their own internet charge online,..
donwload free ebooks - Tuesday 9 November 2010 at 12:51pm
I can distinguish that you are an mavin at your division! I am launching a website soon, and your report will be profoundly valuable for me.. Thanks in search all your help and wishing you all the success.
how to make business cards - Tuesday 9 November 2010 at 12:51pm
Ripping blog! I genuinely love how it' s easy on my eyes as ably as the info are warmly written. I am wondering how I may be notified whenever a stylish send has been made. I possess subscribed to your rss feed which should do the trick! Have a punctilious daytime!
loan calculator - Tuesday 9 November 2010 at 12:51pm
I think one of your advertisements caused my internet browser to resize, you might want to put that on your blacklist.
government grants - Tuesday 9 November 2010 at 12:51pm
I can see that you are an qualified at your division! I am launching a website promptly, and your dope will be profoundly valuable in behalf of me.. Thanks someone is concerned all your alleviate and wishing you all the success.
Cell T Mobile - Tuesday 9 November 2010 at 12:51pm
I went to the dentist a only one weeks ago to participate in my braces on. I' m still having predicament in eating because of the wires. I also observed that I' m having a fortune of cuts clandestine my mouth because of the wires and I upon it precise undesirable.
Medical Claims Examiner - Tuesday 9 November 2010 at 12:51pm
Wonderful blog! I beyond question love how it' s lenient on my eyes as articulately as the evidence are superbly written. I am wondering how I can be notified whenever a further brief has been made. I obtain subscribed to your rss board which essential to do the conspiracy!
Papillary Mesothelioma Cases - Tuesday 9 November 2010 at 12:51pm

One or more comments are waiting for approval by an editor.

Leave a comment