random1 Posted June 27, 2010 Share Posted June 27, 2010 Is there any comprehensive PHP class that converts measuring units like: - meters to feet - cm to inches - pounds to kg I'm working with international weights and dimensions. Quote Link to comment https://forums.phpfreaks.com/topic/205965-unit-conversion-measurement-and-weight-cm-to-inches-meters-to-feet-etc/ Share on other sites More sharing options...
Alex Posted June 27, 2010 Share Posted June 27, 2010 You don't need a class for this, although you could very well make one yourself. There are simple formulas. Example: 1 meter is ~3.280839895 feet, so: function metersToFeet($meters) { return $meters * 3.280839895; } Quote Link to comment https://forums.phpfreaks.com/topic/205965-unit-conversion-measurement-and-weight-cm-to-inches-meters-to-feet-etc/#findComment-1077743 Share on other sites More sharing options...
random1 Posted June 29, 2010 Author Share Posted June 29, 2010 I'm writing a function to convert inches to kilometers. 1 inch = 2.54 × 10-5 kilometers Current Source: if($fromUnit == 'in' && $toUnit == 'km') { return ($value * ?????); } For this example $value = 1 and is an inch. How can I fix: return ($value * ?????); to convert as: 1 inch = 2.54 × 10-5 kilometers Quote Link to comment https://forums.phpfreaks.com/topic/205965-unit-conversion-measurement-and-weight-cm-to-inches-meters-to-feet-etc/#findComment-1078632 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.