名称: units
描述: 使用 GNU Units 进行单位换算与计算。
元数据: {"clawdbot":{"emoji":"📏","requires":{"bins":["units"]}}}
通过命令行使用 GNU units 进行单位换算和计算。可通过包管理器(如 brew 或 apt)安装,包名通常为 "units"。
使用 bash 工具运行 units 命令。使用 -t(简洁)标志可仅输出数值结果。
units -t '原单位' '目标单位'
基础换算:
units -t '10 kg' 'lbs'
# 输出:22.046226
复合单位:
units -t '60 miles/hour' 'm/s'
# 输出:26.8224
温度(非线性换算):
温度换算需使用特定语法:tempF(x)、tempC(x)、tempK(x)。
units -t 'tempF(98.6)' 'tempC'
# 输出:37
时间:
units -t '2 weeks' 'seconds'
输出舍入:
如需舍入到指定小数位数(例如 3 位),使用 -o "%.3f":
units -t -o "%.3f" '10 kg' 'lbs'
# 输出:22.046
定义查询:
要查看单位定义(不进行换算),可省略第二个参数(不使用 -t 标志时输出更详细,适合查看定义):
units '1 acre'
units 支持货币单位(如 USD、EUR 等),但汇率数据可能已过时,因其定义文件中的汇率为静态数据。units -t '1/2 inch' 'mm')。