Skip to content

Function: subtract()

ts
function subtract(a, b): number;

Subtracts second number from first number with fixed precision. 高精度减法运算,避免浮点数误差。

Parameters

ParameterTypeDescription
anumberThe minuend / 被减数
bnumberThe subtrahend / 减数

Returns

number

The result of subtracting b from a / 减法结果

Example

typescript
subtract(0.3, 0.1) // => 0.2 (not 0.19999999999999998)
subtract(123.456, 23.45) // => 100.006

Since

1.0.0

Released under the MIT License.