mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
no value should use decimals (#48155)
This commit is contained in:
parent
fee291c3c8
commit
af8fbc16d6
@ -103,6 +103,9 @@ describe('valueFormats', () => {
|
|||||||
|
|
||||||
expect(toFixed(100.4, 2)).toBe('100.40');
|
expect(toFixed(100.4, 2)).toBe('100.40');
|
||||||
expect(toFixed(100.5, 2)).toBe('100.50');
|
expect(toFixed(100.5, 2)).toBe('100.50');
|
||||||
|
|
||||||
|
expect(toFixed(0, 1)).toBe('0.0');
|
||||||
|
expect(toFixed(0, 2)).toBe('0.00');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -56,6 +56,10 @@ export function toFixed(value: number, decimals?: DecimalCount): string {
|
|||||||
decimals = getDecimalsForValue(value);
|
decimals = getDecimalsForValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value === 0) {
|
||||||
|
return value.toFixed(decimals);
|
||||||
|
}
|
||||||
|
|
||||||
const factor = decimals ? Math.pow(10, Math.max(0, decimals)) : 1;
|
const factor = decimals ? Math.pow(10, Math.max(0, decimals)) : 1;
|
||||||
const formatted = String(Math.round(value * factor) / factor);
|
const formatted = String(Math.round(value * factor) / factor);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user