Skip to content

Commit dde5a04

Browse files
authored
Update number-format.ts
1 parent 7a44614 commit dde5a04

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/number-format.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ export default class NumberFormat {
5454
}
5555

5656
isNull() {
57-
if (this.isClean) {
58-
return !this.numberOnly(this.input, this.cleanRegExp)
59-
}
60-
return !this.numberOnly(this.input, this.negativeRegExp)
57+
return !this.numberOnly((this.isClean ? this.cleanRegExp : this.negativeRegExp)
6158
}
6259

6360
clean(clean = false) {
@@ -77,22 +74,17 @@ export default class NumberFormat {
7774
}
7875

7976
toFixed() {
80-
const padEnd = (num: string) => {
81-
const parts = num.split(this.options.decimal)
82-
parts[1] = parts[1].padEnd(this.options.precision, '0')
83-
return parts.join('')
84-
}
8577
const exp = Math.pow(10, this.options.precision)
86-
const float = parseFloat(padEnd(this.numberOnly())) / exp || 0
78+
const float = parseFloat(this.numberOnly()) / exp || 0
8779
return float.toFixed(fixed(this.options.precision))
8880
}
8981

9082
toNumber(str: Input) {
9183
return Number(str)
9284
}
9385

94-
numberOnly(str?: Input, regExp?: RegExp) {
95-
return (str || this.input)
86+
numberOnly(regExp?: RegExp) {
87+
return this.input
9688
?.toString()
9789
.replace(this.preSurRegExp, '')
9890
.replace(regExp || this.numberRegExp, '')

0 commit comments

Comments
 (0)