feat(config): FormatBytes

This commit is contained in:
web@ppanel 2024-12-13 18:29:30 +07:00
parent 8f322fbcbe
commit 9251a09232
2 changed files with 5 additions and 5 deletions

View File

@ -2,7 +2,7 @@ import { intlFormat } from '@shadcn/ui/lib/date-fns';
export function formatBytes(bytes: number) {
if (bytes === 0) return '0 B';
const k = 1000, // or 1024
const k = 1024, // or 1000
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));

View File

@ -11,13 +11,13 @@ export function unitConversion(
case 'dollarsToCents':
return evaluate(`${value} * 100`);
case 'bitsToMb':
return evaluate(`${value} / 1000 / 1000`);
return evaluate(`${value} / 1024 / 1024`);
case 'mbToBits':
return evaluate(`${value} * 1000 * 1000`);
return evaluate(`${value} * 1024 * 1024`);
case 'bytesToGb':
return evaluate(`${value} / 1000 / 1000 / 1000`);
return evaluate(`${value} / 1024 / 1024 / 1024`);
case 'gbToBytes':
return evaluate(`${value} * 1000 * 1000 * 1000`);
return evaluate(`${value} * 1024 * 1024 * 1024`);
default:
throw new Error('Invalid conversion type');
}