www.LinuxHowtos.org

edit this article

Converting data with units

This short tutorial shows you how to use the units command which is a nifty utility that converts quantities between scales (e.g. meters to feet or kilograms to pounds). While not an essential tool, it can certainly be convenient at times.

Code Listing 1: Getting units

# emerge app-sci/units 
or 
apt-get install units 
or ...

There are two ways to use the units command, interactively and non-interactively. To use it interactively, simply issue the command units.

Code Listing 2: Using units interactively

% units 
1948 units, 71 prefixes, 28 functions 
 
You have: 1 meter 
You want: feet 
        * 3.2808399 
        / 0.3048 
You have: 3 kilograms 
You want: pounds 
        * 6.6138679 
        / 0.15119746

The first number (prefixed by a *) indicates the conversion as you specified (i.e. there are about 3.28 feet in a meter). The second number is the conversion in the opposite direction (i.e. there are about 0.3 meters in a foot).

To use units non-interactively, issue the command followed by the original expression and then the new expression.

Code Listing 3: Using units non-interactively

// How many pecks are in a bushel? 
% units '1 bushel' 'peck' 
        * 4 
        / 0.25 
 
// How many miles per hour are in a knot? 
% units '1 knot' 'mph' 
        * 1.1507794 
        / 0.86897624

Note: A 'knot' is one nautical mile per hour.

See the man page (man units) for more information on the units command.

From http://www.gentoo.org/news/en/gwn/20030825-newsletter.xml


rate this article:
current rating: average rating: 1.1 (14 votes) (1=very good 6=terrible)
Your rating:
Very good (1) Good (2) ok (3) average (4) bad (5) terrible (6)

back