Updating branch refs/heads/master to 83d6f0cae1047d3d4d6989dd7aaa16422739e0ce (commit) from 7dfd6c193d9f2beaeb4005caebf1842a9b45bc3d (commit)
commit 83d6f0cae1047d3d4d6989dd7aaa16422739e0ce Author: Harald Judt <h.j...@gmx.at> Date: Sat Nov 3 20:46:28 2012 +0100 Round temperature to integer value (bug #9318). Round half up for temperatures, according to the "Federal Meteorological Handbook No. 1 - Surface Weather Observations and Reports September 2005", chapter 2.6.3 "Rounding Figures", available at http://www.ofcm.gov/fmh-1/fmh1.htm. As a side-effect, this approach automatically uses a negative zero "-0" for values between -0.5 and 0 which is considered important because in the Celcius scale a value below 0 indicates freezing. This improves readability and saves space. The original floating-point value can still be retrieved via TEMPERATURE_RAW. panel-plugin/weather-data.c | 20 +++++++++++++++++++- panel-plugin/weather-data.h | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c index 6650ab3..ca3e804 100644 --- a/panel-plugin/weather-data.c +++ b/panel-plugin/weather-data.c @@ -78,6 +78,7 @@ get_data(const xml_time *timeslice, case LONGITUDE: return LOCALE_DOUBLE(loc->longitude, "%.4f"); case TEMPERATURE: + case TEMPERATURE_RAW: val = g_ascii_strtod(loc->temperature_value, NULL); if (unit_system == IMPERIAL && (!strcmp(loc->temperature_unit, "celcius") || @@ -86,7 +87,24 @@ get_data(const xml_time *timeslice, else if (unit_system == METRIC && !strcmp(loc->temperature_unit, "fahrenheit")) val = (val - 32.0) * 5.0 / 9.0; - return g_strdup_printf("%.1f", val); + if (type == TEMPERATURE_RAW) { + /* We might want to use the raw temperature value of + * higher precision for calculations. */ + return g_strdup_printf("%.1f", val); + } else { + /* + * Round half up for temperatures, according to the + * "Federal Meteorological Handbook No. 1 - Surface + * Weather Observations and Reports September 2005", + * chapter 2.6.3 "Rounding Figures", available at + * http://www.ofcm.gov/fmh-1/fmh1.htm. As a side-effect, + * this approach automatically uses a negative zero "-0" + * for values between -0.5 and 0, which is considered + * important, as in the Celcius scale a value below 0 + * indicates freezing. + */ + return g_strdup_printf("%.0f", val); + } case PRESSURE: if (unit_system == METRIC) return LOCALE_DOUBLE(loc->pressure_value, "%.1f"); diff --git a/panel-plugin/weather-data.h b/panel-plugin/weather-data.h index 14c4ba3..05d680c 100644 --- a/panel-plugin/weather-data.h +++ b/panel-plugin/weather-data.h @@ -38,7 +38,8 @@ typedef enum { CLOUDINESS, FOG, PRECIPITATIONS, - SYMBOL + SYMBOL, + TEMPERATURE_RAW } data_types; typedef enum { _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits