2011-08-09 132 views
0

我在嘗試將unsigned long long轉換爲double,因爲我需要逗號。unsigned long long to double

NSFileManager* fMgr = [[NSFileManager alloc] init]; 
NSError* pError = nil; 
NSDictionary* pDict = [ fMgr attributesOfFileSystemForPath:NSHomeDirectory() error:&pError ]; 
//get DiskSpace 
NSNumber* pNumAvail = (NSNumber*)[ 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 

我在做什麼錯?

+0

格式說明符錯誤。 –

回答

3

您的格式說明符不匹配。您需要使用浮點格式來打印double。嘗試使用%f而不是%i。不匹配導致未定義的行爲。

+0

-.-非常感謝你,初學者的錯誤... – Seega

2

我認爲你的格式是錯誤的。您應該使用%fNSLog([NSString stringWithFormat:@"%f", tempD]);

+0

另外,一兆字節是1024 * 1024字節! –