Ninjakreborn Posted October 13, 2010 Share Posted October 13, 2010 What is the easiest way in PHP to convert pounds into ounces. So 2.3 pounds would = 35 ounces. Is there an easy way to do this type of conversion? Link to comment https://forums.phpfreaks.com/topic/215819-convert-pounds-to-ounces/ Share on other sites More sharing options...
Alex Posted October 13, 2010 Share Posted October 13, 2010 Yeah, PHP provides built-in support for this kind of thing: math. 1 pound = 16 ounces. $ounces = $pounds * 16; Or create a simple function. function pounds_to_ounces($pounds) { return $pounds * 16; } Link to comment https://forums.phpfreaks.com/topic/215819-convert-pounds-to-ounces/#findComment-1121954 Share on other sites More sharing options...
Ninjakreborn Posted October 13, 2010 Author Share Posted October 13, 2010 Thanks. Link to comment https://forums.phpfreaks.com/topic/215819-convert-pounds-to-ounces/#findComment-1121957 Share on other sites More sharing options...
Ninjakreborn Posted October 13, 2010 Author Share Posted October 13, 2010 According to my tests, that isn't working. If I do 2.5 (2 and a half pounds) and do 2.5 * 16 it's not calculating out correctly. That is what I had originally thought when I tried the conversion the way that was suggested (using standard math) but the values are off for some reason. Link to comment https://forums.phpfreaks.com/topic/215819-convert-pounds-to-ounces/#findComment-1121970 Share on other sites More sharing options...
Alex Posted October 13, 2010 Share Posted October 13, 2010 How is it off? 2.5 * 16 is 40, and 2.5 pounds is 40 ounces. Link to comment https://forums.phpfreaks.com/topic/215819-convert-pounds-to-ounces/#findComment-1121971 Share on other sites More sharing options...
Recommended Posts