English 中文(简体)
Convert NSFileSystemsize to Geabytes
原标题:Convert NSFileSystemSize to Gigabytes

我需要将NSFileSystemSize改为Giabytes。

NSDictionary * fsAttributes = [ [NSFileManager defaultManager]
       fileSystemAttributesAtPath:NSTemporaryDirectory()];
NSNumber *totalSize = [fsAttributes objectForKey:NSFileSystemSize];
NSString *sizeInGB = [NSString stringWithFormat:@"

 %3.2f GB",[totalSize floatValue] / 107374824];

//returns 69.86 GB

是否有任何想法,说明它为什么要回到8.GB?

最佳回答

简称:1024 * 1024:1073741824。 (你在数千处失踪了1人)。

问题回答
- (NSString *)formattedFileSize:(unsigned long long)size
{
    NSString *formattedStr = nil;
    if (size == 0)
        formattedStr = @"Empty";
    else
        if (size > 0 && size < 1024)
            formattedStr = [NSString stringWithFormat:@"%qu bytes", size];
        else
            if (size >= 1024 && size < pow(1024, 2))
                formattedStr = [NSString stringWithFormat:@"%.1f KB", (size / 1024.)];
            else
            if (size >= pow(1024, 2) && size < pow(1024, 3))
                formattedStr = [NSString stringWithFormat:@"%.2f MB", (size / pow(1024, 2))];
            else
                if (size >= pow(1024, 3))
                    formattedStr = [NSString stringWithFormat:@"%.3f GB", (size / pow(1024, 3))];

    return formattedStr;
}




相关问题
Haskell minimum/maximum Double Constant

Is there any way in Haskell to get the constant that is the largest and smallest possible positive rational number greater than zero that can be represented by doubles?

integer automatically converting to double but not float

I have a function like below: void add(int&,float&,float&); and when I call: add(1,30,30) it does not compile. add(1,30.0,30.0) also does not compile. It seems that in both cases, it ...

Lower Bounds For Floating Points

Are there any lower bounds for floating point types in C? Like there are lower bounds for integral types (int being at least 16 bits)?

Floating point again

Yesterday I asked a floating point question, and I have another one. I am doing some computations where I use the results of the math.h (C language) sine, cosine and tangent functions. One of the ...

热门标签