[Profiling] allow negative numbers in formatter (#143420)

* Update as_number.ts

allow negative numbers in formatter. Currently all negative values get truncated to `~0.00`
closes https://github.com/elastic/prodfiler/issues/2707

* Update as_number.ts

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* Update as_number.ts

change negative condition to abs

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Tim Rühsen <tim.ruhsen@elastic.co>
This commit is contained in:
Luca Wintergerst 2022-10-25 11:56:55 +02:00 committed by GitHub
parent 76e9dd4d1f
commit 003bbf7f2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,18 +11,18 @@ export function asNumber(value: number): string {
}
value = Math.round(value * 100) / 100;
if (value < 0.01) {
if (Math.abs(value) < 0.01) {
return '~0.00';
}
if (value < 1e3) {
if (Math.abs(value) < 1e3) {
return value.toString();
}
if (value < 1e6) {
if (Math.abs(value) < 1e6) {
return `${asNumber(value / 1e3)}k`;
}
if (value < 1e9) {
if (Math.abs(value) < 1e9) {
return `${asNumber(value / 1e6)}m`;
}