* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifdef HAVE_MATH_H
#include <math.h>
-#include <glib.h>
+#endif
#include <string.h>
+#include "degrees_converters.h"
#define DEGREE_SYMBOL "\302\260"
tmp = (tmp - val_d) * 60;
val_m = (gint)tmp;
- /* Minutes */
+ /* Seconds */
val_s = (tmp - val_m) * 60;
/* Format */
- result = g_strdup_printf ( "%c%d" DEGREE_SYMBOL "%d'%f\"",
+ result = g_strdup_printf ( "%c%d" DEGREE_SYMBOL "%d'%.4f\"",
sign_c, val_d, val_m, val_s );
return result;
}
gdouble value;
ptr = strpbrk (endptr, "0123456789,.");
if (ptr != NULL) {
- value = g_strtod(ptr, &endptr);
- nbFloat++;
+ const gchar *tmpptr = endptr;
+ value = g_strtod((const gchar *)ptr, (gchar **)&endptr);
+ // Detect when endptr hasn't changed (which may occur if no conversion took place)
+ // particularly if the last character is a ',' or there are multiple '.'s like '5.5.'
+ if ( endptr == tmpptr )
+ break;
+ nbFloat++;
switch(nbFloat) {
case 1:
d = value;
case 3:
s = value;
break;
+ default: break;
}
}
} while (ptr != NULL && endptr != NULL);