diff --git a/package/component/src/component/inputNumber/index.vue b/package/component/src/component/inputNumber/index.vue index ebd76955..2e125629 100644 --- a/package/component/src/component/inputNumber/index.vue +++ b/package/component/src/component/inputNumber/index.vue @@ -11,6 +11,7 @@ import { LayIcon } from "@layui/icons-vue"; import layButton from "../button/index.vue"; import { ref, watch, withDefaults, computed, Ref } from "vue"; import { InputNumberSize } from "./interface"; +import { add, sub } from "./math" export interface InputNumberProps { modelValue?: number; @@ -84,11 +85,11 @@ const maxControl = computed(() => { }); const addition = function () { - num.value += Number(props.step); + num.value = add(num.value, props.step); }; const subtraction = function () { - num.value -= Number(props.step); + num.value = Number(sub(num.value, props.step)); }; const longDown = function (fn: Function) { diff --git a/package/component/src/component/inputNumber/math.ts b/package/component/src/component/inputNumber/math.ts new file mode 100644 index 00000000..4fbc61bd --- /dev/null +++ b/package/component/src/component/inputNumber/math.ts @@ -0,0 +1,21 @@ +//加法 +function add(arg1: number, arg2: number) { + var r1, r2, m; + try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 } + try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 } + m = Math.pow(10, Math.max(r1, r2)) + return (arg1 * m + arg2 * m) / m +} +//减法 +function sub(arg1: number, arg2: number) { + var r1, r2, m, n; + try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 } + try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 } + m = Math.pow(10, Math.max(r1, r2)); + n = (r1 >= r2) ? r1 : r2; + return ((arg1 * m - arg2 * m) / m).toFixed(n); +} +export { + add, + sub, +} \ No newline at end of file diff --git a/package/document-component/src/document/zh-CN/components/inputNumber.md b/package/document-component/src/document/zh-CN/components/inputNumber.md index 5cd72561..a53a15bf 100644 --- a/package/document-component/src/document/zh-CN/components/inputNumber.md +++ b/package/document-component/src/document/zh-CN/components/inputNumber.md @@ -14,7 +14,7 @@ diff --git a/package/document-component/src/document/zh-CN/guide/changelog.md b/package/document-component/src/document/zh-CN/guide/changelog.md index 84efb7c8..e3d339d2 100644 --- a/package/document-component/src/document/zh-CN/guide/changelog.md +++ b/package/document-component/src/document/zh-CN/guide/changelog.md @@ -17,13 +17,13 @@

1.7.6 2022-11-07