Dheeraj Agrawal
Dheeraj Agrawal

Reputation: 2357

OSCommerce USPS convert weight unit from Pound to Ounces

I am working on an OSCommerce site, and for the USPS Shipping method I want to convert the weight unit from Pounds to Ounces, but not getting the way how.

Can anyone help?

Upvotes: 2

Views: 1174

Answers (1)

DaveRandom
DaveRandom

Reputation: 88697

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

Upvotes: 4

Related Questions