unsigned long long to double
I am trying to convert an unsigned long long
to a double
, because I need the comma.
NSFileManager* fMgr = [[NSFileManager alloc] init];
NSError* pError = nil;
NSDictionary* pDict = [ fMgr attributesOfFileSystemForPath:NSHomeDirectory() error:&pError ];
//get DiskSpace
NSNumber* pNumAvail = (NSN开发者_高级运维umber*)[ pDict objectForKey:NSFileSystemSize ];
[fMgr release];
//byte to Mega byte
unsigned long long temp = [pNumAvail unsignedLongLongValue]/1000000;
//Mega byte to kilo byte
double tempD = (double)(temp/1000.0);
NSLog([NSString stringWithFormat:@"%qu", temp]); //result 63529
NSLog([NSString stringWithFormat:@"%i", tempD]); //result 1168231105
///////////////////////////////////////////////////but i want 63.529
What am I doing wrong?
You are mismatching your format specifier. You need to use a floating-point format to print a double
. Try using %f
instead of %i
. The mismatch causes undefined behaviour.
I think your format is wrong. You should use %f
: NSLog([NSString stringWithFormat:@"%f", tempD]);
精彩评论