Skip to content

Commit 79c1c7f

Browse files
mingmingwonyyx990803
authored andcommitted
fine-tuning of toNumber function (vuejs#4684)
1. parseFloat() support only one param, see MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat 2. maybe it's better to use isNaN() to judge the conversion result?
1 parent 104b940 commit 79c1c7f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/shared/util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export function _toString (val: any): string {
1616
* If the conversion fails, return original string.
1717
*/
1818
export function toNumber (val: string): number | string {
19-
const n = parseFloat(val, 10)
20-
return (n || n === 0) ? n : val
19+
const n = parseFloat(val)
20+
return isNaN(n) ? val : n
2121
}
2222

2323
/**

0 commit comments

Comments
 (0)