precisionNumber
解决数字运算时精度问题(最高支持到16位)
Demo
+
= 0
-
= 0
x
= 0
÷
= NaN
Usage
ts
<template>
<div class="">
<!-- 加 -->
<input
v-model="addObj.a"
type="number"
style="border: 1px solid greenyellow"
/>
<div style="display: inline-block; margin: 0px 10px">+</div>
<input
v-model="addObj.b"
type="number"
style="border: 1px solid greenyellow"
/>
<div style="display: inline-block; margin: 0px 10px">= {{ addObj.c }}</div>
</div>
</template>
<script lang="ts" setup>
import { reactive, computed } from 'vue'
import { precisionNumber } from '@morehook/utils'
const addObj: any = reactive({
a: 0,
b: 0,
c: computed(() => {
return precisionNumber.add(addObj.a, addObj.b)
})
})
</script>
Type Declarations
typescript
declare function add(a: number, b: number, digits?: number): number
declare function subtract(a: number, b: number, digits?: number): number
declare function multiply(a: number, b: number, digits?: number): number
declare function divide(a: number, b: number, digits?: number): number
export declare const precisionNumber: {
add: typeof add
subtract: typeof subtract
multiply: typeof multiply
divide: typeof divide
}