trim_dec.c 766 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * \file trim_dec.c
  3. *
  4. * \brief GIS Library - Trim string decimal functions.
  5. *
  6. * (C) 2001-2008 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 GRASS GIS Development Team
  12. *
  13. * \date 1999-2008
  14. */
  15. #include <grass/gis.h>
  16. /**
  17. * \brief Removes trailing zeros from decimal number.
  18. *
  19. * Example: 23.45000 would come back as 23.45
  20. *
  21. * \param[in,out] buf
  22. * \return always returns 0
  23. */
  24. int G_trim_decimal(char *buf)
  25. {
  26. char *mark;
  27. /* find the . */
  28. while (*buf != '.')
  29. if (*buf++ == 0)
  30. return 0;
  31. mark = buf;
  32. while (*++buf)
  33. if (*buf != '0')
  34. mark = buf + 1;
  35. *mark = 0;
  36. return 0;
  37. }