fork(8) download
  1. #include <stdio.h>
  2. #include <math.h>
  3. char toNotationUnit(double value,float *out) {
  4. double val;
  5. char notacoes[] = {'y','z','a','f','p','n','u','m',' ','k','M','G','T','P','E','Z','Y'};
  6. int counter=8;
  7. char unit;
  8. val = value>0?value:-value;
  9. if(val < 1) {
  10. while( (val < 1.00) & (counter != 0)) {
  11. counter--;
  12. val=val*(double)1000;
  13. }
  14. }else{
  15. while((val >= 1000) & (counter != 16)) {
  16. counter++;
  17. val=val/(double)1000;
  18. }
  19. }
  20. unit = notacoes[counter];
  21. val = round(val*(double)100)/(double)100;
  22. *out = (float) value>0?val:-val;
  23. return unit;
  24. }
  25.  
  26. int main() {
  27. double x = -1230000;
  28. float res;
  29. char t;
  30. t = toNotationUnit(x,&res);
  31. printf("%.2F%c",res,t);
  32. return 0;
  33. }
stdin
Standard input is empty
compilation info
prog.c: In function ‘toNotationUnit’:
prog.c:21: warning: implicit declaration of function ‘round’
prog.c:21: warning: incompatible implicit declaration of built-in function ‘round’
stdout
-1.23M