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>
This commit is contained in:
jahnli 2024-07-09 00:01:20 +08:00 committed by GitHub
parent 09af7eae1a
commit 01b20dd1be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 3 deletions

View File

@ -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

View File

@ -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`

View File

@ -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)
}