mirror of
https://github.com/NotAShelf/nix-evaluator-stats.git
synced 2026-04-27 12:25:20 +00:00
various: eliminate floating-point noise before displaying
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ic14f4c0a9e0bcbe3460bbecc670f713d6a6a6964
This commit is contained in:
parent
6102e75a9e
commit
d26a70dacd
3 changed files with 16 additions and 6 deletions
|
|
@ -6,10 +6,11 @@ export function formatBytes(bytes: number, precision = 2): string {
|
|||
}
|
||||
|
||||
export function formatNumber(num: number, precision = 2): string {
|
||||
if (num >= 1e9) return (num / 1e9).toFixed(precision) + 'B';
|
||||
if (num >= 1e6) return (num / 1e6).toFixed(precision) + 'M';
|
||||
if (num >= 1e3) return (num / 1e3).toFixed(precision) + 'K';
|
||||
return num.toString();
|
||||
if (num >= 1e9) return parseFloat((num / 1e9).toFixed(precision)).toString() + 'B';
|
||||
if (num >= 1e6) return parseFloat((num / 1e6).toFixed(precision)).toString() + 'M';
|
||||
if (num >= 1e3) return parseFloat((num / 1e3).toFixed(precision)).toString() + 'K';
|
||||
const factor = Math.pow(10, precision);
|
||||
return (Math.round(num * factor) / factor).toString();
|
||||
}
|
||||
|
||||
export function formatTime(seconds: number, precision = 2): string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue