Advertisement
Advertisement
| 02.21.2008 at 09:37PM PST, ID: 23183623 | Points: 500 |
|
[x]
Attachment Details
|
||
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 02.21.2008 at 09:48PM PST, ID: 20954968 |
| 02.21.2008 at 10:00PM PST, ID: 20955008 |
| 02.22.2008 at 08:43PM PST, ID: 20963700 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: |
- (NSString *)reduceBytes:(long long)bytes {
int type = 0;
long long reducedBytes = bytes;
while(reducedBytes > 1024) {
reducedBytes = bytes / 1024;
type++;
}
NSString *returnString;
switch(type) {
case 0:
returnString = [ NSString stringWithFormat: @"%lld", reducedBytes ];
break;
case 1:
returnString = [ NSString stringWithFormat: @"%f KB", (float)(((int)(reducedBytes * 10)) /10) ];
break;
case 2:
returnString = [ NSString stringWithFormat: @"%f MB", (float)(((int)(reducedBytes * 10)) /10) ];
break;
case 3:
returnString = [ NSString stringWithFormat: @"%f GB", (float)(((int)(reducedBytes * 10)) /10) ];
break;
}
return returnString;
}
|
| 02.23.2008 at 04:22AM PST, ID: 20964683 |
| 02.23.2008 at 07:18AM PST, ID: 20965209 |
| 02.23.2008 at 08:07AM PST, ID: 20965393 |
| 02.23.2008 at 09:03AM PST, ID: 20965637 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: |
NSString *reduceBytes(unsigned long bytes) {
const char *suffixTable[] = {"bytes", "KB", "MB", "GB", "TB", NULL};
/*
if (bytes == 1) {
return @"1 byte";
}
*/
int suffixIdx = 0;
double reducedBytes = (double)bytes;
while (reducedBytes >= 1000.0 && suffixTable[suffixIdx + 1] != NULL) {
suffixIdx++;
reducedBytes /= 1024.0;
}
return [ NSString stringWithFormat: @"%.1f %s", reducedBytes, suffixTable[suffixIdx] ];
}
|
| 02.26.2008 at 08:30AM PST, ID: 20985835 |