Skip to content

Commit

Permalink
Tweak behaviour and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaydelaney committed May 31, 2022
1 parent f003994 commit e2a65e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Expand Up @@ -21,7 +21,7 @@ describe('valueFormats', () => {
${'currencyIDR'} | ${2} | ${1532.82} | ${'Rp1.53K'}
${'none'} | ${undefined} | ${3.23} | ${'3.23'}
${'none'} | ${undefined} | ${0.0245} | ${'0.0245'}
${'none'} | ${undefined} | ${1 / 3} | ${'0.333'}
${'none'} | ${undefined} | ${1 / 3} | ${'0.3333333333333333'}
${'ms'} | ${4} | ${0.0024} | ${'0.0024 ms'}
${'ms'} | ${0} | ${100} | ${'100 ms'}
${'ms'} | ${2} | ${1250} | ${'1.25 s'}
Expand Down
10 changes: 9 additions & 1 deletion packages/grafana-data/src/valueFormats/valueFormats.ts
Expand Up @@ -43,7 +43,15 @@ let categories: ValueFormatCategory[] = [];
const index: ValueFormatterIndex = {};
let hasBuiltIndex = false;

export function toNumber(value: number): FormattedValue {
export function toNumber(value: number | null, decimals?: DecimalCount): FormattedValue {
if (value === null) {
return { text: '' };
}

if (decimals !== undefined && decimals !== null) {
return { text: value.toFixed(decimals) };
}

return { text: value.toString() };
}

Expand Down

0 comments on commit e2a65e5

Please sign in to comment.