Function createUnit #

创建用户定义的单位并将其注册到 Unit 类型。

Syntax #

math.createUnit({
  baseUnit1: {
    aliases: [string, ...]
    prefixes: object
  },
  unit2: {
    definition: string,
    aliases: [string, ...]
    prefixes: object,
    offset: number
  },
  unit3: string    // Shortcut
})

Parameters #

Parameter Type Description
name string 新单位的名称。必须是唯一的。示例:“knot”
definition string, UnitDefinition, Unit 根据现有单位定义的单位。例如,“0.514444444 m / s”。
options Object (optional) An object containing any of the following properties:</br>- prefixes {string} “none”, “short”, “long”, “binary_short”, or “binary_long”。默认值为“none”。</br>- aliases {Array} 字符串数组。示例:[‘knots’, ‘kt’, ‘kts’]</br>- offset {Numeric} 从单位转换时应用的偏移量。例如,摄氏度的偏移量为 273.15。默认值为 0。

Returns #

Type Description
单位 新单位

Throws #

Type | Description —- | ———–

Examples #

math.createUnit('foo')
math.createUnit('knot', {definition: '0.514444444 m/s', aliases: ['knots', 'kt', 'kts']})
math.createUnit('mph', '1 mile/hour')
math.createUnit('km', math.unit(1000, 'm'))

另请参阅 #

unit

Fork me on GitHub