Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonas Witt
committed
May 18, 2008
1 parent
6d8f5be
commit a0ee0f3
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// NSNumber+Units.h | ||
// Sparkle | ||
// | ||
// Created by Jonas Witt on 5/18/08. | ||
// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface NSNumber (Units) | ||
|
||
+ (NSString *)humanReadableSizeFromDouble:(double)value; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// NSNumber+Units.m | ||
// Sparkle | ||
// | ||
// Created by Jonas Witt on 5/18/08. | ||
// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "NSNumber+Units.h" | ||
|
||
|
||
@implementation NSNumber (Units) | ||
|
||
+ (NSString *)humanReadableSizeFromDouble:(double)value | ||
{ | ||
if (value < 1024) | ||
return [NSString stringWithFormat:@"%ul", value]; | ||
|
||
if (value < 1024 * 1024) | ||
return [NSString stringWithFormat:@"%.0lf KB", value / 1024.0]; | ||
|
||
if (value < 1024 * 1024 * 1024) | ||
return [NSString stringWithFormat:@"%.1lf MB", value / 1024.0 / 1024.0]; | ||
|
||
return [NSString stringWithFormat:@"%.2lf GB", value / 1024.0 / 1024.0 / 1024.0]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters