Skip to content

Commit

Permalink
Bytes as MB formatting were off by a factor 1024!
Browse files Browse the repository at this point in the history
Also change constants from bits (b) to bytes (B).
  • Loading branch information
tobli committed Feb 25, 2017
1 parent a25a08e commit 4ed8a52
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ts/helpers/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ export function formatDateLocalized(date: Date): string {
return `${date.toUTCString()}</br>(local time: ${date.toLocaleString()})`;
}

const bytesPerKb = 1024;
const bytesPerMb = 1024 * bytesPerKb;
const bytesPerKB = 1024;
const bytesPerMB = 1024 * bytesPerKB;

export function formatBytes(bytes: number): string {
const raw = `${bytes} bytes`;
if (bytes >= bytesPerMb) {
return `${raw} (~${roundNumber(bytes / bytesPerKb, 1)} MB)`;
if (bytes >= bytesPerMB) {
return `${raw} (~${roundNumber(bytes / bytesPerMB, 1)} MB)`;
}
if (bytes >= bytesPerKb) {
return `${raw} (~${roundNumber(bytes / bytesPerKb, 0)} kB)`;
if (bytes >= bytesPerKB) {
return `${raw} (~${roundNumber(bytes / bytesPerKB, 0)} kB)`;
}
return raw;
}
Expand Down

0 comments on commit 4ed8a52

Please sign in to comment.