mirror of
https://github.com/NotAShelf/nix-evaluator-stats.git
synced 2026-04-27 04:17:36 +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 {
|
||||
|
|
|
|||
|
|
@ -303,7 +303,13 @@ const ComparisonView: Component<ComparisonViewProps> = props => {
|
|||
<Show when={!row.isReduction}>
|
||||
<ArrowUpIcon size={14} />
|
||||
</Show>
|
||||
{Math.abs(row.change).toFixed(prec())}%
|
||||
{parseFloat(
|
||||
(
|
||||
Math.round(Math.abs(row.change) * Math.pow(10, prec())) /
|
||||
Math.pow(10, prec())
|
||||
).toFixed(prec()),
|
||||
)}
|
||||
%
|
||||
</span>
|
||||
</Show>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,10 @@ const ThunkChart: Component<ThunkChartProps> = props => {
|
|||
<div class="ratio-bar">
|
||||
<div class="ratio-fill" style={{ width: `${avoidedRatio() * 100}%` }} />
|
||||
</div>
|
||||
<span class="ratio-label">Avoidance rate: {(avoidedRatio() * 100).toFixed(prec())}%</span>
|
||||
<span class="ratio-label">
|
||||
Avoidance rate:{' '}
|
||||
{Math.round(avoidedRatio() * 100 * Math.pow(10, prec())) / Math.pow(10, prec())}%
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue