From 01b20dd1be228b44a70167bd5e96817169a4b03c Mon Sep 17 00:00:00 2001 From: jahnli Date: Tue, 9 Jul 2024 00:01:20 +0800 Subject: [PATCH] fix(input-number): exception when the value is a string with precision set (#6094) * fix(n-input-number): exception when the value is a string in precision mode * Apply suggestions from code review * Update src/input-number/src/utils.ts --------- Co-authored-by: 07akioni <07akioni2@gmail.com> --- CHANGELOG.en-US.md | 6 +++++- CHANGELOG.zh-CN.md | 7 ++++++- src/input-number/src/utils.ts | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index ea2471b36..4b52df217 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -2,7 +2,11 @@ ## NEXT_VERSION -`NEXT_VERSION` +`xxxx-xx-xx` + +### Fixes + +- Fix `n-input-number` Exception when the value is a string in precision mode, closes [#6091](https://github.com/tusen-ai/naive-ui/issues/6091). ### Features diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 596ddf867..85845a1e4 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -2,12 +2,17 @@ ## NEXT_VERSION -`NEXT_VERSION` +`xxxx-xx-xx` + +### Fixes + +- 修复 `n-input-number` precision 模式下 value 为字符串时的异常问题,关闭 [#6091](https://github.com/tusen-ai/naive-ui/issues/6091) ### Features - `n-input-number` 新增 `round` 属性,关闭 [#6097](https://github.com/tusen-ai/naive-ui/issues/6097) + ## 2.38.2 `2024-05-03` diff --git a/src/input-number/src/utils.ts b/src/input-number/src/utils.ts index 308cb7461..0127aaae7 100644 --- a/src/input-number/src/utils.ts +++ b/src/input-number/src/utils.ts @@ -34,7 +34,7 @@ export function format ( value: number | undefined | null, precision: number | undefined ): string { - if (value === undefined || value === null) return '' + if (typeof value !== 'number') return '' return precision === undefined ? String(value) : value.toFixed(precision) }