Hi,
I’ve been wondering how Apple calculates Gigabytes in Finder, as I haven’t been able to find any function that yields the result shown.
I would like to convert 1,303,412,493 Bytes.
It says 1.3 GB in the top right corner, which matches my own conversion.
let byteCountFormatStyle = ByteCountFormatStyle(style: .file,
allowedUnits: .all,
spellsOutZero: false,
includesActualByteCount: false,
locale: Locale.current)
let sizeFormatStyle = byteCountFormatStyle.format(Int64(1_303_412_493))
let byteMeasurement = Measurement(value: Double(1_303_412_493), unit: UnitInformationStorage.bytes)
let sizeMeasurement = byteMeasurement.formatted(.byteCount(style: .file))
print("sizeFormatStyle: \(sizeFormatStyle), sizeMeasurement: \(sizeMeasurement)")Both are the same: sizeFormatStyle: 1.3 GB, sizeMeasurement: 1.3 GB
But how do I arrive at the 1.51 GB figure that appears next to the Byte count?
Christian
Topic:
App & System Services
SubTopic:
Core OS
Tags:
Foundation
Swift
Files and Storage
Internationalization
2
0
317