Skip to content

Commit

Permalink
Fix #379 to use formatNumber to reduce unnecessary decimal places
Browse files Browse the repository at this point in the history
  • Loading branch information
alainbryden committed Oct 21, 2024
1 parent b903489 commit c0e97b9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export function formatRam(num, printGB) {
} else if (idx < 0) {
idx = 0;
}
return (num / 1000 ** idx).toFixed(3).toLocaleString('en') + " " + memorySuffixes[idx];
const scaled = num / 1000 ** idx; // Scale the number to the order of magnitude chosen
// Only display decimal places if there are any
const formatted = scaled - Math.round(scaled) == 0 ? Math.round(scaled) : formatNumber(num / 1000 ** idx);
return formatted.toLocaleString('en') + " " + memorySuffixes[idx];
}

/** Return a datatime in ISO format */
Expand Down

0 comments on commit c0e97b9

Please sign in to comment.