(bytes: number)
| 178 | // Storage unit conversion, parameter unit is b |
| 179 | // Rule: normal conversion, do not do 1 processing |
| 180 | export 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. |
no test coverage detected