[Xfce4-commits] <xfce4-weather-plugin:master> Add common function to format double to ascii string.
Harald Judt
noreply at xfce.org
Sat Jan 5 12:04:05 CET 2013
Updating branch refs/heads/master
to 751224afa3fd3be27c56d37c13c76af42100bcd4 (commit)
from 5e2b39acadfa4f23388d942346cc0b86e7056d7d (commit)
commit 751224afa3fd3be27c56d37c13c76af42100bcd4
Author: Harald Judt <h.judt at gmx.at>
Date: Fri Dec 21 11:11:28 2012 +0100
Add common function to format double to ascii string.
panel-plugin/weather-data.c | 14 +++++++++++++-
panel-plugin/weather-data.h | 3 +++
2 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index fb31f35..4c930ee 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -93,7 +93,7 @@ typedef struct {
/* convert string to a double value, returning backup value on error */
gdouble
string_to_double(const gchar *str,
- gdouble backup)
+ const gdouble backup)
{
gdouble d = backup;
if (str && strlen(str) > 0)
@@ -102,6 +102,18 @@ string_to_double(const gchar *str,
}
+/* convert double to string, using non-local format */
+gchar *
+double_to_string(const gdouble val,
+ const gchar *format)
+{
+ gchar buf[20];
+ return g_strdup(g_ascii_formatd(buf, 20,
+ format ? format : "%.1f",
+ val));
+}
+
+
gchar *
format_date(const time_t date_t,
gchar *format,
diff --git a/panel-plugin/weather-data.h b/panel-plugin/weather-data.h
index d0115b8..03be37c 100644
--- a/panel-plugin/weather-data.h
+++ b/panel-plugin/weather-data.h
@@ -90,6 +90,9 @@ typedef struct {
gdouble string_to_double(const gchar *str,
gdouble backup);
+gchar *double_to_string(gdouble val,
+ const gchar *format);
+
gchar *format_date(const time_t t,
gchar *format,
gboolean local);
More information about the Xfce4-commits
mailing list