Join Kevin Skoglund for an in-depth discussion in this video Challenge: Convert to and from metric mass, part of Easy PHP Projects: Measurement Conversion.
- View Offline
- Now that we have our mass conversion form all set up,…we're ready to do the code that actually…does the conversion for us.…We've already said that the common unit…of measurement we're going to use is the kilogram,…so all we need is the conversion constant…to get from each unit into kilograms.…We have a chart here, and you can see it has…ounce, pound, stone, long ton and short ton,…and the conversion numbers we need to get to kilograms.…I want to make a few other notes on these units, though.…Ounce here is a unit of mass.…We also saw it used as a unit…of volume measurement earlier.…The volume version is sometimes called fluid ounce,…in order to avoid confusion.…
In this case, they're on separate pages, clearly marked…as being volume and mass, so I think it's OK.…If you want, you can change it into fluid ounce…in order to avoid confusion.…Pound is probably the most commonly used…of the Imperial and US measures,…the one that you're most familiar with,…then there's stone, which is still used in some places…but also considered a bit old-fashioned.…
Along the way, series designer Kevin Skoglund introduces coding strategies, refactoring techniques, and useful skills including dynamically generating form select-option values and formatting decimal numbers and scientific notation.
- Converting length and area measurements
- Using functions to avoid repetition
- Refactoring to produce simpler code
- Converting volume and mass
- Generating form select-option values dynamically
- Formatting scientific notation
- Converting speed and temperature