Advertisement
ByMsx

Untitled

Jun 15th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. char* format(char* x)
  2. {
  3.     int e;
  4.     char z[64], s[64];
  5.  
  6.     if(x[0] == '-') {
  7.         x = x + 1;
  8.         z[0] = '-';
  9.     }
  10.  
  11.     while(x[0] = '0')
  12.         x = x + 1;
  13.  
  14.     while(x[e] != '.')
  15.         e++;
  16.  
  17.     if(e == 0)
  18.     {
  19.         while(x[1] == '0')
  20.         {
  21.             e--;
  22.             memmove (x+1, x+2, strlen (x+2));
  23.         }
  24.     }
  25.     memmove(x + 1 + e, x + 2 + e, strlen(x + 2 + e));
  26.     e--;
  27.     memmove(x + 2, x + 3, strlen(x + 2));
  28.     x[1] = '.';
  29.     x[6] = 0;
  30.     while(strlen(x) < 4)
  31.         strcat(x, "0");
  32.  
  33.     itoa(e, s, 64);
  34.     char *result = new char[64];
  35.     memset(result, 0, 64);
  36.     memcpy(result, z, strlen(z));
  37.     strcat(result, x);
  38.     strcat(result, "E");
  39.     strcat(result, s);
  40.     return result;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement