Skip to content

Commit 66c2eac

Browse files
author
Dipak Sarkar
committed
updated formatter
1 parent aff3025 commit 66c2eac

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/number-format.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ export default function NumberFormat(config = options) {
5757
}
5858

5959
this.realNumber = () => {
60-
const number = this.numbers().toString().replace(this.options.decimal, '.')
61-
if (this.options.reverseFill) {
62-
return number
63-
}
64-
return this.toNumber(number)
60+
return this.numbers().toString().replace(this.options.decimal, '.')
6561
}
6662

6763
this.parts = (number = '', decimal = this.options.decimal) => {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import NumberFormat from '../../src/number-format'
2+
3+
describe('when enabled reverse fill', () => {
4+
const numberFormat = new NumberFormat({
5+
minimumFractionDigits: 2
6+
})
7+
it('should return as follows', () => {
8+
expect(numberFormat.clean(true).format('55468')).toEqual('55,468.00')
9+
expect(numberFormat.clean(true).format('55468.5')).toEqual('55,468.50')
10+
expect(numberFormat.clean(true).format('55468.546-')).toEqual('-55,468.55')
11+
expect(numberFormat.clean(true).format('-1234.6512')).toEqual('-1,234.65')
12+
})
13+
it('should return as follows', () => {
14+
expect(numberFormat.clean(true).unformat('55468')).toEqual('55468.00')
15+
expect(numberFormat.clean(true).unformat('55468.50')).toEqual('55468.50')
16+
expect(numberFormat.clean(true).unformat('55468.546-')).toEqual('-55468.55')
17+
expect(numberFormat.clean(true).unformat('-1234.6512')).toEqual('-1234.65')
18+
})
19+
})
20+
21+

0 commit comments

Comments
 (0)