How to convert pounds or grams to kilograms in php?
In this post, The function converter helps you convert grams, pounds to kilograms in PHP
1. Code:
<?php
function convertWeightToKg($unit, $weight){
switch (strtolower($unit)) {
case "g":
$conv = 1000;
break;
case "lb":
$conv = 2.20462262;
break;
default:
$conv = 1;
break;
}
$weight = $weight / $conv;
return $weight;
}
echo convertWeightToKg("lb", 10);
echo convertWeightToKg("g", 12000);
?>
2. Example:
Input:
Input 1: Weight unit: lb , Weight = 10 Input 2: Weight unit: g , Weight = 12000
Output:
Output 1: 4.5359237 Output 2: 12