format.c 887 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /****************************************************************************
  2. *
  3. * MODULE: r.coin
  4. *
  5. * AUTHOR(S): Michael O'Shea - CERL
  6. * Michael Shapiro - CERL
  7. *
  8. * PURPOSE: Calculates the coincidence of two raster map layers.
  9. *
  10. * COPYRIGHT: (C) 2006 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. ***************************************************************************/
  17. #include <stdio.h>
  18. #include <string.h>
  19. int format_double(double v, char *buf, int n)
  20. {
  21. char fmt[15];
  22. int k;
  23. sprintf(fmt, "%%%d.2lf", n);
  24. sprintf(buf, fmt, v);
  25. for (k = n; strlen(buf) > n; k--) {
  26. sprintf(fmt, "%%%d.%dg", n, k);
  27. sprintf(buf, fmt, v);
  28. }
  29. return 0;
  30. }