I got a file size in byte in a (unsigned long long)
variable. Is there a standard way to convert it to a string, with localized units?
I am aware of those kind of solutions :
NSString * stringFromFileSize( FileSize theSize )
{
float floatSize = theSize;
if (theSize<1023)
return ([NSString stringWithFormat:@"%i bytes",theSize]);
floatSize = floatSize / 1024;
if (floatSize<1023)
return ([NSString stringWithFormat:@"%1.1f KB",floatSize]);
floatSize = floatSize / 1024;
if (floatSize<1023)
return ([NSString stringWithFormat:@"%1.1f MB",floatSize]);
floatSize = floatSize / 1024;
return([NSString stringWithFormat:@"%1.1f GB",floatSize]);
}
But it doesn't work in French, where 'octet' is used instead of bytes (and all B from the units have to be replaced by an 'o'). I've searched around CFLocalGetValue
, looked at all formatting methods I know about without any success, so is there any hidden method/function to help me? I can manage to build something by hand, but I would prefere avoiding it.