Skip to content

Commit

Permalink
fix toNumber #57
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Nov 5, 2023
1 parent a47bd0c commit 070eaa9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion func/helperCreateToNumber.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function helperCreateToNumber (handle) {
return function (str) {
if (str) {
var num = handle(str)
var num = handle(str && str.replace ? str.replace(/,/g, '') : str)
if (!isNaN(num)) {
return num
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xe-utils",
"version": "3.5.13",
"version": "3.5.14",
"description": "JavaScript 函数库、工具类",
"main": "index.js",
"unpkg": "dist/xe-utils.umd.min.js",
Expand Down
12 changes: 12 additions & 0 deletions test/number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,9 @@ describe('Number functions', () => {
expect(
XEUtils.toNumberString('123.33')
).toEqual('123.33')
expect(
XEUtils.toNumberString('12,345.33')
).toEqual('12,345.33')
expect(
XEUtils.toNumberString(1e-9)
).toEqual('0.000000001')
Expand Down Expand Up @@ -875,6 +878,15 @@ describe('Number functions', () => {
expect(
XEUtils.toNumber('12.3')
).toEqual(12.3)
expect(
XEUtils.toNumber('12,345')
).toEqual(12345)
expect(
XEUtils.toNumber('12,345.33')
).toEqual(12345.33)
expect(
XEUtils.toNumber('12,345,678.33')
).toEqual(12345678.33)
expect(
XEUtils.toNumber('12456456.66663')
).toEqual(12456456.66663)
Expand Down

0 comments on commit 070eaa9

Please sign in to comment.