I am working in an OSCommerce site, for USPS Shipping method I want to convert weight Unit from Pounds to Ounces, but not getting the way, can anyone help?
Thanks in advance
Given that 1 pound = 16 ounces, you can basically just multiply it by 16:
$pounds = 8;
$ounces = $pounds * 16;
echo $ounces; // 128
...but, if pounds is a float, you will probably want to round it. Since you are talking about shipping weights, you probably want to round up:
$pounds = 8.536;
$ounces = ceil($pounds * 16);
echo $ounces; // 137
You could put this into a function, like this:
function pounds_to_ounces ($pounds) {
return ceil($pounds * 16);
}
echo pounds_to_ounces(8); // 128
echo pounds_to_ounces(8.536); // 137