-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* CB-3443 add format number util function * CB-3443 format number from 1k * CB-3443 include 1k in formatting --------- Co-authored-by: Evgenia Bezborodova <[email protected]>
- Loading branch information
1 parent
5f26449
commit 1d5dc14
Showing
3 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2023 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
|
||
export function formatNumber(n: number, d: number) { | ||
if (n < 1000) { | ||
return n.toString(); | ||
} | ||
|
||
const numStr = n.toString(); | ||
const exponent = numStr.length - (numStr.length % 3); | ||
|
||
const power = Math.pow(10, d); | ||
const rounded = Math.round((n * power) / Math.pow(10, exponent)) / power; | ||
|
||
const units = ' kMBTPE'; | ||
const unit = units[exponent / 3]; | ||
|
||
return rounded + unit; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters