units of measurement

May 1st, 2007 mysurface Posted in bc, Common, Misc, units | Hits: 35420 | 3 Comments »

To measure a quantitative object, we usually use certain standard of units. To measure width or length of a piece of paper, we may use inches, centimeter or meter. Sometimes, the conversion between one system unit to another might not be straight forward. For examples convert inch to cm approximately, 1 inch is 2.54cm, 1 cm is 0.3937 inch.

With units, we can convert from one unit to another, e.g. 2.25 inch to cm.

units 2.25inch cm

The result will looks like this:

* 5.715
/ 0.17497813

First line, is the result in cm. The second line is the inversion, It means (2.25 times 0.17497813) inch will be approximately 1 cm. Check it with bc,

echo "2.25*0.17497813" | bc -l

What if I just want the converted results to be printed? Make use of head, cut and pipelines.

units 2.25inch cm | head -n1 | cut -f2 -d' '

By the way, I discovered there exist online unit converter, WWW Unit Converter, which is pretty cool.

[中文翻译]

3 Responses to “units of measurement”

  1. You can also perform online conversion via Google: 2.25 inch to cm

  2. You are right Carlos, and also for calculation. I did this on google

    2.26*PI*5^2

    That’s amazing, thanks Carlos.

  3. Hi, I am newbie.This is my frist post …lol.
    say hi to everybody.

Leave a Reply