Skip to content

Commit

Permalink
Merge pull request #62 from CiprianoFreitas/master
Browse files Browse the repository at this point in the history
[bug-fix] fixed numeral with zero decimal places - fixes #57
  • Loading branch information
nosir authored Jul 22, 2016
2 parents 14d938c + b5f644b commit 42df649
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/common/DefaultProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var DefaultProperties = {

// numeral
target.numeral = !!opts.numeral;
target.numeralDecimalScale = opts.numeralDecimalScale || 2;
target.numeralDecimalScale = opts.numeralDecimalScale === 0 ? 0 : opts.numeralDecimalScale || 2;
target.numeralDecimalMark = opts.numeralDecimalMark || '.';
target.numeralThousandsGroupStyle = opts.numeralThousandsGroupStyle || 'thousand';

Expand Down
5 changes: 3 additions & 2 deletions src/shortcuts/NumeralFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var NumeralFormatter = function (numeralDecimalMark,
var owner = this;

owner.numeralDecimalMark = numeralDecimalMark || '.';
owner.numeralDecimalScale = numeralDecimalScale || 2;
owner.numeralDecimalScale = numeralDecimalScale === 0 ? 0 : numeralDecimalScale || 2;
owner.numeralThousandsGroupStyle = numeralThousandsGroupStyle || NumeralFormatter.groupStyle.thousand;
owner.delimiter = (delimiter || delimiter === '') ? delimiter : ',';
owner.delimiterRE = delimiter ? new RegExp('\\' + delimiter, 'g') : '';
Expand Down Expand Up @@ -47,7 +47,8 @@ NumeralFormatter.prototype = {
if (value.indexOf(owner.numeralDecimalMark) >= 0) {
parts = value.split(owner.numeralDecimalMark);
partInteger = parts[0];
partDecimal = owner.numeralDecimalMark + parts[1].slice(0, owner.numeralDecimalScale);
if(owner.numeralDecimalScale > 0)
partDecimal = owner.numeralDecimalMark + parts[1].slice(0, owner.numeralDecimalScale);
}

switch (owner.numeralThousandsGroupStyle) {
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/numeral.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@
]
]
},
{
"numeralDecimalScale": 0,
"numbers": [
[
"12.3456789",
"12"
],
[
"12.3",
"12"
]
]
},
{
"numeralDecimalScale": 3,
"numbers": [
Expand Down

0 comments on commit 42df649

Please sign in to comment.