Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

27 lines
637 B

  1. #include "fmt.h"
  2. size_t fmt_humank(char* dest,unsigned long long l) {
  3. char unit;
  4. size_t i;
  5. if (l<1000) return fmt_ulong(dest,l);
  6. if (l>1024*1024*1024*1024ull) {
  7. l=(l+(1024*1024*1024*1024ull/20))/(1024*1024*1024*1024ull/10);
  8. unit='T';
  9. } else if (l>1024*1024*1024) {
  10. l=(l+(1024*1024*1024/20))/(1024*1024*1024/10);
  11. unit='G';
  12. } else if (l>1024*1024) {
  13. l=(l+(1024*1024/20))/(1024*1024/10);
  14. unit='M';
  15. } else {
  16. l=(l+(1024/20))/(1024/10);
  17. unit='k';
  18. }
  19. if (!dest) return fmt_ulong(0,l)+2;
  20. i=fmt_ulong(dest,l/10);
  21. dest[i]='.';
  22. dest[i+1]=(char)((l%10)+'0');
  23. dest[i+2]=unit;
  24. return i+3;
  25. }