Skip to content

floatMul

浮点数乘法,用于处理浮点数乘法并保持精度。

引入

js
import { floatMul } from '@/uni_modules/lime-shared/floatMul'

示例

js
// 示例1:正确相乘两个浮点数,返回8
console.log(floatMul(2.0, 4.0));  // 输出:8

// 示例2:相乘两个浮点数,其中一个有小数,返回7.5
console.log(floatMul(3.0, 2.5));  // 输出:7.5

// 示例3:传递非数字类型参数,将警告并返回NaN
console.log(floatMul('a' as any, 2.0));  // 输出:NaN,并控制台警告

// 示例4:相乘两个浮点数,其中一个为0,将返回0
console.log(floatMul(0, 10.123));  // 输出:0

// 示例5:相乘两个浮点数,返回0.333
console.log(floatMul(1/3, 1));  // 输出:0.3333333333333333,但实际结果可能因精度问题而略有不同