Skip to content

Commit

Permalink
ver. 0.1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
qili.taoqili committed May 21, 2019
1 parent 45f0383 commit ca26d4a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
15 changes: 9 additions & 6 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
## 0,1.11
## 0.1.12
* `FIXED` fix bug when fixNum is 0

## 0.1.11

* `CHANGED` remove useless dependency `object-assign`, `prop-types`

# 0.1.9
* `CHANGED` use `big.js` instead of `parseFloat` to handle large number fixed

# 0.1.8
* `CHANGED` undefined/null/'' return ''
* `CHANGED` undefined/null/'' return ''
* because they are all invalid value for date.

# 0.1.7
* `CHANGED` null check

# 0.1.6
* `CHANGED` fit React@15
* `CHANGED` delete 'package-lock.json' file
* `CHANGED` fit React@15
* `CHANGED` delete 'package-lock.json' file
# 0.1.3

* `CHANGED` eslint
* `CHANGED` eslint
* `CHANGED` add tests
* `CHANGED` use default delimeter only delimeter is undefined

Expand All @@ -27,4 +30,4 @@

# 0.1.1

`CHANGED` more rational money formatter
`CHANGED` more rational money formatter
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uxcore-formatter",
"version": "0.1.11",
"version": "0.1.12",
"description": "a formatter library for uxcore",
"repository": "https://github.com/uxcore/uxcore-formatter.git",
"author": "eternalsky",
Expand Down Expand Up @@ -36,7 +36,7 @@
"console-polyfill": "^0.2.2",
"enzyme": "^3.0.0",
"enzyme-adapter-react-16": "1.x",
"expect.js": "~0.3.1",
"expect.js": "^0.3.1",
"kuma-base": "1.x",
"react": "16.x",
"react-dom": "16.x",
Expand All @@ -49,4 +49,4 @@
},
"contributors": [],
"license": "MIT"
}
}
2 changes: 1 addition & 1 deletion src/Formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Formatter.date = (str, pattern) => {

Formatter.money = (str, delimiter = ' ', fixedNum) => {
// const actualStr = fixedNum ? parseFloat(str).toFixed(fixedNum).toString() : str;
const actualStr = fixedNum ? new Big(str).toFixed(parseInt(fixedNum, 10)).toString() : str;
const actualStr = (fixedNum || fixedNum === 0) ? new Big(str).toFixed(parseInt(fixedNum, 10)).toString() : str;
if (actualStr.indexOf('.') !== -1) {
return actualStr.replace(/(\d)(?=(?:\d{3})+(\.))/g, (match, $1) => $1 + delimiter)
.replace(/(\d{3})(?![$|\.|\(|\s])/g, (match, $1) => $1);
Expand Down
1 change: 1 addition & 0 deletions tests/Formatter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('Formatter.money', () => {

it('works with fixed number', () => {
expect(Formatter.money('100', ',', 0)).to.be('100');
expect(Formatter.money('100.1', ',', 0)).to.be('100');
expect(Formatter.money('100', ',', 2)).to.be('100.00');
expect(Formatter.money('1000000000.8888', ',', 2)).to.be('1,000,000,000.89');
expect(Formatter.money('1000000000.99', ',', 5)).to.be('1,000,000,000.99000');
Expand Down

0 comments on commit ca26d4a

Please sign in to comment.