We seem to have a mix of cyclists including ones who use metric/SI units of measurement and ones who use British Imperial/US units of measurement.

I have found it convenient in the past when writing trip reports to embed scripts in my web-site that let viewers choose which kind of units they want to see (many yanks like myself prefer SI distances when calculating grades, but can't let go of Fahrenheit). I automatically detect quantities (number + unit) in text and convert them and then use CSS styling to show whichever they prefer.

I polished that into an Apache2 licensed project and you can see the result at the demo page.


Does bicycles.se think automatic unit conversion would be helpful? If so I'm happy to help the admins integrate it.

I have written unit-systems for electro-mechanical simulation software before, but this is a much scaled down version and was done specifically for cycling discussions, so it comes with some caveats. From the source comments:

// This script does not attempt to
// - infer the difference between delta temperatures and absolute temperatures,
//   e.g. "The temperature dropped 5 celsius" should be
//        "The temperature dropped 9 fahrenheit" not
//        "The temperature dropped 41 fahrenheit"
//   though the web page author may give hints:
//   <span class="unit-delta">5 celsius</span>.
// - convert other unit types or handle arbitrary unit expressions N/m2.
// - handle non-English text.
// - handle numbers written in non-US non-British style with a comma as the
//   decimal point: "1.000,5 kg".
// - distinguish between pounds-mass and pounds-force.
// - deal with extremely precise measurements.
//   Results are formatted to 3 decimal places.
// - convert precisions : 5 m +/- 2 cm.
// - normalize units : .1 lbs -> 45.4 g instead of 0.0454 kg.
// - distinguish between different Imperial and US measures with the same
//   name.  Most of these are volumetric (oz, quart, gallon) or obscure.
// - convert between inches and cm because those are often used in
//   cycling as speced numbers.
//   Per http://sheldonbrown.com/tire-sizing.html
//     Bicycle tires come in a bewildering variety of sizes.
//     To make matters worse, in the early days of cycling,
//     every country that manufactured bicycles developed
//     its own system of marking the sizes. These different
//     national sizing schemes created a situation in which
//     the same size tire would be known by different numbers
//     in different countries. Even worse, different-sized
//     tires that were not interchangeable with one another
//     were often marked with the same numbers!
  • I like the idea, but I'm not sure it's practical in the real world. How would you differentiate between units which must remain the same, i.e. tire sizes, and units which are flexible, like temperatures, weights and distances? Perhaps it would be better to implement the conversion in a rollover tip box, so that if you want a conversion, you can easily get it, but it's not automatic for those things that should remain at a specific number.
    – zenbike
    May 30, 2012 at 4:45
  • Also, are you suggesting implementing a user preferences pane on the profile page that would allow selection of units for each type of measurement? How else would you deal with folks like me who can't get Celsius measurement conversion to be automatic in my head, despite living in a metric environment for several years, while routinely using Metric unit standards for everything else. And would you also include the option for British standard measurements?
    – zenbike
    May 30, 2012 at 4:48
  • @zenbike, please see the last caveat: "This script does not attempt to ... convert between inches and cm because those are often used in cycling as speced numbers" so it won't affect tire or wrench sizes. May 30, 2012 at 14:58
  • @zenbike, I am not suggesting a specific UI. One option would be a rollover as you suggest : show SI in rollover for Imperial units and vice-versa. Another option is a discrete drop-down like the one on the demo page that possibly is initialized based on a user preference. May 30, 2012 at 15:01
  • 2
    Since it's just JavaScript, why not package it up as a userscript and publish it on stackapps?
    – nhinkle
    Jun 3, 2012 at 19:21
  • @nhinkle, I didn't know stackapps existed. Thanks. Jun 3, 2012 at 21:44

1 Answer 1


I like the idea of doing some automatic unit conversion, or providing tools for automatically converting units. Adding parenthetical lbs, kg, mi, km, tempF, tempC, etc is a common edit on questions and answers, in order to increase the audience. Many things on our site deal with physical measurement units. Many people only understand one unit system or the other, or simply have a better feel for one or the other.

However, I see a few problems with your plan of dropping that JS in place:

  1. Surprise changes to the text could be confusing and end up with things like "3 miles (4.82 km) (5 km (3.13 miles))". We want to be very careful with anything that effectively changes the markup (or any behavior) on our site to be different from other sites in the Stack Exchange network.
  2. Your script adds significant digits inappropriately. "5 km" should convert to "3 miles" or maybe "3.1" miles, never "3.13" or "3.11". Adding more than 1 significant digit is just wrong, since it adds implied accuracy. Counting the significant digits of the input and using that many significant digits (or 1 more) on output would be a good start.
  3. Your conversions are wrong. I only checked one, but you have 0.626 as the km to miles conversion, and it should be 0.62137 or 0.621.
  4. Doing it automatically is always going to get it a bit wrong now and then. Some uses of inches and cm (such as heights) should be converted, even though (as you point out) some shouldn't. The difference is in context, not anything a computer will be able to automatically detect reliably. Anything that excludes certain simple units while automatically handling others will confuse people.

Ways I could see automatic conversion working well:

  • A feature for assisting people in converting units, and make it available on all SE sites that routinely need such conversions. Perhaps a button that when you highlight text like "5 inches" changes it to "5 inches (13 cm)".
  • An automatic system that subtly highlighted units with a known conversion and displayed the conversion on mouse hover. Similar to how dates are handled now, where "3 hours ago" on hover displays "2012-05-30 15:01:06Z".

Here's some examples of posts where unit conversion would probably be (or have been) helpful:

  • If the significant digits are the dealbreaker, I can fix. The meaning of significant digits in "1 1/3 miles" is iffy, but I can do a fixed number of sig-digits for fractions and preserve significant digits otherwise. The script currently displays units on hover using uformat conventions for measures. If desired, I can change it to do only that -- no changes to the text in the body of the page. May 31, 2012 at 20:06
  • 1
    "A feature for assisting people in converting units, and make it available on all SE sites that routinely need such conversions." Can do if desired. Is that a question for meta.SO? May 31, 2012 at 20:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .