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. 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; } 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 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
Archived
This topic is now archived and is closed to further replies.