Skip to content

Commit

Permalink
fix: exclude negative sign from digit group separation (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
amcgee authored Sep 14, 2020
1 parent 857b3f0 commit d7ec310
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/__demo__/PivotTable.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ storiesOf('PivotTable', module).add('simple', () => {
)
})

storiesOf('PivotTable', module).add('simple - comma DGS', () => {
const visualization = {
...simpleVisualization,
...visualizationReset,
digitGroupSeparator: 'COMMA',
}
return (
<div style={{ width: 800, height: 600 }}>
<PivotTable data={simpleData} visualization={visualization} />
</div>
)
})

storiesOf('PivotTable', module).add(
'simple - title / subtitle / filter',
() => {
Expand Down
8 changes: 4 additions & 4 deletions src/__demo__/data/simple.data.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"fbfJHSPpUQD",
"201907",
"ImspTQPwCqd",
"22356.0",
"461.0",
"",
"",
"",
Expand All @@ -89,7 +89,7 @@
"testing-extraneous-data",
"201907",
"ImspTQPwCqd",
"22356.0",
"1234.0",
"",
"",
"",
Expand All @@ -100,7 +100,7 @@
"fbfJHSPpUQD",
"201905",
"ImspTQPwCqd",
"29461.0",
"-461.0",
"",
"",
"",
Expand All @@ -111,7 +111,7 @@
"fbfJHSPpUQD",
"201904",
"ImspTQPwCqd",
"18576.0",
"-1234.0",
"",
"",
"",
Expand Down
7 changes: 6 additions & 1 deletion src/modules/pivotTable/renderValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ const trimTrailingZeros = stringValue => stringValue.replace(/\.?0+$/, '')
const defaultDecimalSeparator = '.'

const separateDigitGroups = (stringValue, decimalSeparator) => {
const [integer, remainder] = stringValue.split('.')
const isNegative = stringValue[0] === '-'
const [integer, remainder] = stringValue.replace(/^-/, '').split('.')

const groups = []
for (let i = integer.length; i > 0; i -= 3) {
groups.unshift(integer.substring(i - 3, i))
}

if (isNegative) {
groups[0] = '-' + groups[0]
}

if (remainder) {
const trimmedRemainder = trimTrailingZeros(remainder)
if (trimmedRemainder.length) {
Expand Down

0 comments on commit d7ec310

Please sign in to comment.