why does division of NSNumber by float gives result rounded to 1 decimal place?
-
01-07-2021 - |
質問
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);
所属していません StackOverflow