diff --git a/src/portal/src/app/shared/units/utils.spec.ts b/src/portal/src/app/shared/units/utils.spec.ts index 4d24a4b020..04c8869b68 100644 --- a/src/portal/src/app/shared/units/utils.spec.ts +++ b/src/portal/src/app/shared/units/utils.spec.ts @@ -60,13 +60,15 @@ describe('functions in utils.ts should work', () => { expect(getSizeNumber(10)).toEqual(10); expect(getSizeNumber(456400)).toEqual('445.70'); expect(getSizeNumber(45640000)).toEqual('43.53'); + expect(getSizeNumber(4564000000000)).toEqual('4.15'); }); it('function getSizeUnit() should work', () => { expect(getSizeUnit).toBeTruthy(); - expect(getSizeUnit(4564)).toEqual('KB'); + expect(getSizeUnit(4564)).toEqual('KiB'); expect(getSizeUnit(10)).toEqual('Byte'); - expect(getSizeUnit(4564000)).toEqual('MB'); - expect(getSizeUnit(4564000000)).toEqual('GB'); + expect(getSizeUnit(4564000)).toEqual('MiB'); + expect(getSizeUnit(4564000000)).toEqual('GiB'); + expect(getSizeUnit(4564000000000)).toEqual('TiB'); }); }); diff --git a/src/portal/src/app/shared/units/utils.ts b/src/portal/src/app/shared/units/utils.ts index 8a1e617c31..7d11c31fb8 100644 --- a/src/portal/src/app/shared/units/utils.ts +++ b/src/portal/src/app/shared/units/utils.ts @@ -569,11 +569,13 @@ export const validateLimit = unitContrl => { export function formatSize(tagSize: string): string { let size: number = Number.parseInt(tagSize); if (Math.pow(1024, 1) <= size && size < Math.pow(1024, 2)) { - return (size / Math.pow(1024, 1)).toFixed(2) + "KB"; + return (size / Math.pow(1024, 1)).toFixed(2) + "KiB"; } else if (Math.pow(1024, 2) <= size && size < Math.pow(1024, 3)) { - return (size / Math.pow(1024, 2)).toFixed(2) + "MB"; + return (size / Math.pow(1024, 2)).toFixed(2) + "MiB"; } else if (Math.pow(1024, 3) <= size && size < Math.pow(1024, 4)) { - return (size / Math.pow(1024, 3)).toFixed(2) + "GB"; + return (size / Math.pow(1024, 3)).toFixed(2) + "GiB"; + } else if (Math.pow(1024, 4) <= size && size < Math.pow(1024, 5)) { + return (size / Math.pow(1024, 4)).toFixed(2) + "TiB"; } else { return size + "B"; } @@ -590,6 +592,8 @@ export function getSizeNumber(size: number): string | number { return (size / Math.pow(1024, 2)).toFixed(2); } else if (Math.pow(1024, 3) <= size && size < Math.pow(1024, 4)) { return (size / Math.pow(1024, 3)).toFixed(2); + } else if (Math.pow(1024, 4) <= size && size < Math.pow(1024, 5)) { + return (size / Math.pow(1024, 4)).toFixed(2); } else { return size; } @@ -601,11 +605,13 @@ export function getSizeNumber(size: number): string | number { */ export function getSizeUnit(size: number): string { if (Math.pow(1024, 1) <= size && size < Math.pow(1024, 2)) { - return "KB"; + return "KiB"; } else if (Math.pow(1024, 2) <= size && size < Math.pow(1024, 3)) { - return "MB"; + return "MiB"; } else if (Math.pow(1024, 3) <= size && size < Math.pow(1024, 4)) { - return "GB"; + return "GiB"; + } else if (Math.pow(1024, 4) <= size && size < Math.pow(1024, 5)) { + return "TiB"; } else { return "Byte"; }