Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix htsmsg_json_write() to write HMF_DBL values correctly. Update hts…

…msg_get_dbl() to handle string and int values
  • Loading branch information...
commit 0e8b006adb96d449551e506da8cedbf1db19c872 1 parent ce67dd9
@jsm174 authored
Showing with 13 additions and 4 deletions.
  1. +12 −2 src/htsmsg.c
  2. +1 −2  src/htsmsg_json.c
14 src/htsmsg.c
@@ -405,10 +405,20 @@ htsmsg_get_dbl(htsmsg_t *msg, const char *name, double *dblp)
if((f = htsmsg_field_find(msg, name)) == NULL)
- if(f->hmf_type != HMF_DBL)
+ switch(f->hmf_type) {
+ default:
+ case HMF_DBL:
+ *dblp = f->hmf_dbl;
+ break;
+ case HMF_S64:
+ *dblp = f->hmf_s64;
+ break;
+ case HMF_STR:
+ *dblp = strtod(f->hmf_str, NULL);
+ break;
+ }
- *dblp = f->hmf_dbl;
return 0;
3  src/htsmsg_json.c
@@ -26,7 +26,6 @@
#include "htsmsg_json.h"
#include "htsbuf.h"
#include "misc/json.h"
-#include "misc/dbl.h"
@@ -75,7 +74,7 @@ htsmsg_json_write(htsmsg_t *msg, htsbuf_queue_t *hq, int isarray,
case HMF_DBL:
- my_double2str(buf, sizeof(buf), f->hmf_dbl);
+ snprintf(buf, sizeof(buf), "%f", f->hmf_dbl);
andoma added a note

You can't change this as it will become locale dependent. For example in Sweden it will print as "3,1415" instead of "3.1415"

Same with strtod().

Any reason why misc/dbl.h won't work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
htsbuf_append(hq, buf, strlen(buf));

4 comments on commit 0e8b006


Hello. I was using dbl to store latitude and longitudes. There is a precision issue occurring. If I enter a value of 1.4, it gets sent back to the webui (via htsmsg_json) as 1.3999999901.

I asked about this on IRC:


I'm wondering if I should change my internal values to be strings.

Was TVH supposed to be locale independent, ie always decimal points for doubles?


Yeah well that's why I added the dbl.[ch] code in the first place to avoid locale issues (in particular in JSON)

Passing values as strings is probably OK i guess.


Just asking the question.

I personally hate the idea of storing numbers as strings.

Looks like other c libraries (json-c) face the same locale issues.

I guess if my_double2str gets fixed, we'll be good. The HMF_STR case I added to htsmsg.c isn't really needed. I did however need the HMF_S64 case so integer values would be converted and not return HTSMSG_ERR_CONVERSION_IMPOSSIBLE.

Please sign in to comment.
Something went wrong with that request. Please try again.