Skip to content

Commit

Permalink
[Profiling] allow negative numbers in formatter (#143420)
Browse files Browse the repository at this point in the history
* Update as_number.ts

allow negative numbers in formatter. Currently all negative values get truncated to `~0.00`
closes elastic/prodfiler#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 <[email protected]>
Co-authored-by: Tim Rühsen <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2022
1 parent 76e9dd4 commit 003bbf7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions x-pack/plugins/profiling/public/utils/formatters/as_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}

Expand Down

0 comments on commit 003bbf7

Please sign in to comment.