Skip to content

Home > robinson > calc

calc() function

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

数值计算

Signature:

typescript
declare function calc(number1: BigSource, number2: BigSource, operate?: TOperate): string;
declare function calc(number1: BigSource, number2: BigSource, operate?: TOperate): string;

Parameters

ParameterTypeDescription
number1BigSource第一个数字。
number2BigSource第二个数字。
operateTOperate(Optional) 操作符,默认为 '+'。

Returns:

string

{number} - 计算结果。

Example

javascript
calc(0.1, 0.2);// 返回 0.3
calc(0.1, 0.2, '-');// 返回 -0.1
calc(0.1, 0.2, '*');// 返回 0.02
calc(0.1, 0.2, '/');// 返回 0.5
calc(0.1, 0.2);// 返回 0.3
calc(0.1, 0.2, '-');// 返回 -0.1
calc(0.1, 0.2, '*');// 返回 0.02
calc(0.1, 0.2, '/');// 返回 0.5

Released under the MIT License.