why does division of NSNumber by float gives result rounded to 1 decimal place?
见以下代码:
1 2 | NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize]; float totalSpaceInMB = (([fileSystemSizeInBytes longLongValue] /1024.0)/1024.0); |
这里
例如,如果
我想要 4 位小数,
1 2 3 4 5 | NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize]; double totalSpaceInMB = (([fileSystemSizeInBytes longLongValue] /1024.0)/1024.0); NSLog(@"%.4f",totalSpaceInMB); |
希望这会有所帮助:)
最好尝试一下:
1 2 3 | NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize]; double totalSpaceInMB = (([fileSystemSizeInBytes longLongValue] /1024.0)/1024.0); NSLog(@"%.4lf",totalSpaceInMB); |