CooCooWakka : UsingUnits

首页 :: 索引 :: 修订历史 :: 最新评论 :: CooCooWakkaGroup :: 登陆/注册 :: 你好, 38.103.63.62
你的足迹: » UsingUnits
Converting data with units

This week's tip 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 9.1: Getting units

# emerge app-sci/units
  

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

Code listing 9.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 9.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.
当前页面没有留言.[显示留言板]

SourceForge.net Logo Creative Commons License
请享受共创成果的同时,尊重他人劳动。本站点内容如未特别声明,全部遵循 Creative Commons License by-nc-sa协议发布。