How to convert Kilograms (KG) into pounds, and pounds into stones with PHP

This tutorial will discuss how Kilograms (KG) can be converted into stones or Pounds with PHP. Especially the stones are easy to calculate from KG, once the number of pounds has been established. For the sake of accuracy this in-between step can be seen as a necessary one.

First let's have a look at a simple straightforward conversion from Kilograms to Pounds. As you can see from the following example this is accomplished by multiplying the number of kilos times 2.2:

<?php

\$kg = 80;

\$pounds = \$kg * 2.2;

echo \$pounds." Pounds";

?>

The result will of the above calculation will be 176 Pounds. Next up we will convert those 176 Pounds back into KG with a simple division:

<?php

\$pounds = 176;

\$kg = \$pounds / 2.2;

echo \$kg." KG";

?>

Now if we were to convert pounds into stone we would have to divide the number of pounds by 14, as the number of pounds inside a stones adds up to that amount:

<?php

\$pounds = 176;

\$stones = \$pounds / 14;

echo \$stones." Stones";

?>

To convert stones into pounds we can multiply the number of stones by 14:

<?php

\$stones = 12.5;

\$pounds = \$stones * 14;

echo \$pounds." Pounds";

?>

And there you have it, converting Kilos into Pounds, and Pounds into Stones is a piece of cake with PHP!