I'm trying to use (NS)Measurement
to convert any higher unit into kilobytes
.
let mes = Measurement(value: 3, unit: UnitInformationStorage.megabytes)
let kilobytes = mes.converted(to: .kilobytes).value
I expect kilobytes to be 3072
, but instead I get 3000
.
I get that in computing we often do rounding and for many people 1000 kilobytes = 1MB when in reality it should be 1024 kilobytes = 1MB. Is there any way to change this behavior?
That’s the correct and documented behavior: the kilobytes
and megabytes
units are powers of 10. For powers of 2, use kibibytes
and mebibytes
.