MCPcopy Create free account
hub / github.com/apitable/apitable / normalByteMGArr

Function normalByteMGArr

packages/core/src/utils/number.ts:180–195  ·  view source on GitHub ↗
(bytes: number)

Source from the content-addressed store, hash-verified

178// Storage unit conversion, parameter unit is b
179// Rule: normal conversion, do not do 1 processing
180export function normalByteMGArr(bytes: number) {
181 const i = Math.floor(Math.log(bytes) / Math.log(1024));
182 if (i < 2) {
183 const res = normalDecimal(bytes / Math.pow(1024, 2));
184 return [res, CapacityUnit[2]];
185 }
186 if (i === 2 || i === 3) {
187 const res = normalDecimal(bytes / Math.pow(1024, i));
188 return (res === 1024 && i === 2) ? [1, CapacityUnit[i + 1]] : [res, CapacityUnit[i]];
189 }
190 if (i > 3) {
191 const res = normalDecimal(bytes / Math.pow(1024, 3));
192 return [res.toLocaleString(), CapacityUnit[3]];
193 }
194 return [normalDecimal(bytes), CapacityUnit[0]];
195}
196
197// Storage unit conversion, parameter unit is b
198// Rule: The decimal point is advanced by 1, and one place is reserved after the decimal point.

Callers 1

CapacityFunction · 0.90

Calls 2

normalDecimalFunction · 0.85
logMethod · 0.45

Tested by

no test coverage detected