From 8c8bf81c61d4da00bfd529f92a394f59a1b1f5b7 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Sat, 6 Oct 2001 14:23:10 +0000 Subject: New function that parses a string as a double either in the C locale or 2001-10-06 Christopher James Lahey * gal/util/e-util.c, gal/util/e-util.h (e_flexible_strtod): New function that parses a string as a double either in the C locale or the current locale. (e_ascii_dtostr): New function that saves a double as a string as it would be saved in the C locale. * gal/util/e-xml-utils.c (e_xml_get_double_prop_by_name_with_default): Use e_flexible_strtod here. (e_xml_set_double_prop_by_name): Use e_ascii_dtostr here. svn path=/trunk/; revision=13479 --- e-util/e-xml-utils.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'e-util/e-xml-utils.c') diff --git a/e-util/e-xml-utils.c b/e-util/e-xml-utils.c index 1285b5ce75..6ff68c5904 100644 --- a/e-util/e-xml-utils.c +++ b/e-util/e-xml-utils.c @@ -30,6 +30,7 @@ #include #include #include "gal/util/e-i18n.h" +#include "gal/util/e-util.h" xmlNode * e_xml_get_child_by_name (const xmlNode *parent, const xmlChar *child_name) @@ -329,7 +330,7 @@ e_xml_get_double_prop_by_name_with_default (const xmlNode *parent, const xmlChar prop = xmlGetProp ((xmlNode *) parent, prop_name); if (prop != NULL) { - (void) sscanf (prop, "%lf", &ret_val); + ret_val = e_flexible_strtod (prop, NULL); xmlFree (prop); } return ret_val; @@ -338,18 +339,17 @@ e_xml_get_double_prop_by_name_with_default (const xmlNode *parent, const xmlChar void e_xml_set_double_prop_by_name(xmlNode *parent, const xmlChar *prop_name, gdouble value) { - gchar *valuestr; + char buffer[E_ASCII_DTOSTR_BUF_SIZE]; g_return_if_fail (parent != NULL); g_return_if_fail (prop_name != NULL); if (fabs (value) < 1e9 && fabs (value) > 1e-5) { - valuestr = g_strdup_printf ("%f", value); + e_ascii_dtostr (buffer, sizeof (buffer), "%.17f", value); } else { - valuestr = g_strdup_printf ("%.*g", DBL_DIG, value); + e_ascii_dtostr (buffer, sizeof (buffer), "%.17g", value); } - xmlSetProp (parent, prop_name, valuestr); - g_free (valuestr); + xmlSetProp (parent, prop_name, buffer); } gchar * -- cgit v1.2.3