See the following code:

NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize];
float totalSpaceInMB = (([fileSystemSizeInBytes longLongValue] /1024.0)/1024.0);

Here totalSpaceInMB is always rounded off to 1 decimal place.

For example, if fileSystemSizeInBytes = 13261987840, then totalSpaceInMB = 12647.6

I want 4 decimal places, totalSpaceInMB = 12647.6172. Why is this happening?

有帮助吗?

解决方案

NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize];

double totalSpaceInMB = (([fileSystemSizeInBytes longLongValue] /1024.0)/1024.0);

NSLog(@"%.4f",totalSpaceInMB);

Hope this helps :)

其他提示

Better Try out :

NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize];
double totalSpaceInMB = (([fileSystemSizeInBytes longLongValue] /1024.0)/1024.0);
NSLog(@"%.4lf",totalSpaceInMB);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top