trim_dec.c 811 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*!
  2. * \file lib/gis/trim_dec.c
  3. *
  4. * \brief GIS Library - Trim string decimal functions.
  5. *
  6. * (C) 2001-2009 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public License
  9. * (>=v2). Read the file COPYING that comes with GRASS for details.
  10. *
  11. * \author Original author CERL
  12. */
  13. #include <string.h>
  14. #include <grass/gis.h>
  15. /*!
  16. * \brief Removes trailing zeros from decimal number.
  17. *
  18. * Example: 23.45000 would come back as 23.45
  19. *
  20. * \param[in,out] buf
  21. */
  22. void G_trim_decimal(char *buf)
  23. {
  24. char *mark;
  25. /* don't trim e+20 into e+2 */
  26. if( strchr(buf, 'e') || strchr(buf, 'E') )
  27. return;
  28. /* find the . */
  29. while (*buf != '.')
  30. if (*buf++ == 0)
  31. return;
  32. mark = buf;
  33. while (*++buf)
  34. if (*buf != '0')
  35. mark = buf + 1;
  36. *mark = 0;
  37. }