Skip to content

Function: divide()

ts
function divide(a, b): number;

Divides first number by second number with fixed precision. 高精度除法运算,避免浮点数误差。

Parameters

ParameterTypeDescription
anumberThe dividend / 被除数
bnumberThe divisor / 除数

Returns

number

The result of dividing a by b / 除法结果

Throws

Error if divisor is zero / 如果除数为零则抛出错误

Example

typescript
divide(0.3, 0.1) // => 3 (not 2.9999999999999996)
divide(123.456, 12.3) // => 10.037073170731707
divide(5, 0) // throws Error

Since

1.0.0

Released under the MIT License.