Question

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?

Was it helpful?

Solution

NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize];

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

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

Hope this helps :)

OTHER TIPS

Better Try out :

NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize];
double totalSpaceInMB = (([fileSystemSizeInBytes longLongValue] /1024.0)/1024.0);
NSLog(@"%.4lf",totalSpaceInMB);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top