GRASS 8 Programmer's Manual 8.6.0dev(2026)-55de52a352
Loading...
Searching...
No Matches
trim_dec.c
Go to the documentation of this file.
1/*!
2 * \file lib/gis/trim_dec.c
3 *
4 * \brief GIS Library - Trim string decimal functions.
5 *
6 * SPDX-FileCopyrightText: 2001-2009 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author Original author CERL
10 */
11
12#include <string.h>
13#include <grass/gis.h>
14
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 */
22void G_trim_decimal(char *buf)
23{
24 char *mark;
25
26 /* don't trim e+20 into e+2 */
27 if (strchr(buf, 'e') || strchr(buf, 'E'))
28 return;
29
30 /* find the . */
31 while (*buf != '.')
32 if (*buf++ == 0)
33 return;
34
35 mark = buf;
36 while (*++buf)
37 if (*buf != '0')
38 mark = buf + 1;
39 *mark = 0;
40}
void G_trim_decimal(char *buf)
Removes trailing zeros from decimal number.
Definition trim_dec.c:22