Is there a simple way to do something like..
[NSMagicDataConverter humanStringWithBytes:20000000]
..which would return “19.1MB”?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s my own take on the problem:
By default (if
0is passed forflags), it will output SI units (base ten). You can setkUnitStringBinaryUnitsto select binary (base two) units suitable for memory, orkUnitStringOSNativeUnitsto have the unit type selected automatically based on OS version (pre-Leopard gets base two, post-Leopard gets base ten). SettingkUnitStringLocalizedFormatformats the string based on the user’s current locale. For example:Here’s the helper function required for OS-native units: