Skip to content

Commit

Permalink
Merge branch 'master' into FDG-9941
Browse files Browse the repository at this point in the history
  • Loading branch information
jdach committed Jan 14, 2025
2 parents f357bfd + 9811284 commit 573a330
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/charts/chart-primary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let w,
svgDefs,
roundingDenomination;

const baseYAxisWidth = 66;
const baseYAxisWidth = 72;

const chartDimensions = {
height: 360,
Expand Down
11 changes: 10 additions & 1 deletion src/helpers/simplify-number/simplifyNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ export default function simplifyNumber(n, currency, ignoreDecimal) {
}
}
} else if (letter === ' B') {
rounded = sections > 1 ? Math.round(Math.abs(n) / simplifier) : new Intl.NumberFormat('en-US').format(Math.round(Math.abs(n)));
const absVal = Math.abs(n);
if (absVal < 1e10) {
let singleDigitBillionsVal = (absVal / 1e9).toFixed(1);
if (singleDigitBillionsVal.endsWith('.0')) {
singleDigitBillionsVal = singleDigitBillionsVal.slice(0, -2);
}
rounded = singleDigitBillionsVal;
} else {
rounded = Math.round(absVal / simplifier);
}
} else {
rounded = sections > 1 ? Math.round((Math.abs(n) / simplifier) * 10) / 10 : new Intl.NumberFormat('en-US').format(Math.round(Math.abs(n)));
}
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/simplify-number/simplifyNumber.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ describe('simplify number', () => {
it('handles billions', () => {
expect(simplifyNumber(123193123123.23)).toBe('123 B'); //also validates rounding
});
it('handles billions', () => {
expect(simplifyNumber(12319312312.23)).toBe('12 B'); //also validates rounding
});
it('handles billions', () => {
expect(simplifyNumber(1231931231.23)).toBe('1.2 B'); //also validates rounding
});

it('handles millions', () => {
expect(simplifyNumber(123123123.23)).toBe('123.1 M');
Expand Down

0 comments on commit 573a330

Please sign in to comment.