I want to make an online measurement converter for my company’s intranet page. I am torn about how to handle the converting and wanted some opinions.
Basically the user would enter some random measurement and select what type of measurement that is and what they want it converted to. For example 12 Inches = 1 Foot or 12 Feet = 365.76 centimeter
Version 1
Do I enter each conversion factor possible?
1 centimeter = 0.03280839895 feet
1 centimeter = 0.3937007874 inch
1 centimeter = 0.01 meter
1 feet = 30.48 centimeter
1 feet = 12 inch
1 feet = 0.3048 meter
and so on.
If this is the case then if I have 10 possible choices then I would have 100 different formulas to hard code.

Version 2
Do I convert what ever number they enter to say centimeters and then convert the centimeters to what ever they wanted outputted to them.
I think this would only be 20 formulas then. Ten to get you to centimeters and 10 to get you back out.

Hopefully that makes sense.

4 Years
Discussion Span
Last Post by k9huey

option 2 sounds preferable to me. Once you know what something is in meters, it's just a matter of multiplying or dividing by units of 10. Knowing the relationship between all the metric units is fairly rudimentary since they all stand as units of 10s, but keeping US standard units straight is a little more tracking.

I would start by defining some constants that don't change to use as comparators, starting with METER since it's the base unit. I would then try to just calculate all the relationships at once maybe and then just return what they requested.


Hopefully I will be able to start this project next week. I was leaning more towards option 2. Thanks for the comment.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.