[collectd] Commas as a thousand separator

Lee Essen lee.essen at nowonline.co.uk
Tue Feb 1 12:51:16 CET 2011


Hi Octo,

On Mon, Jan 31, 2011 at 05:40:06PM +0000, Lee Essen wrote:
> > Looking at the code for the curl plugin and then utils_match.c it just
> > does a strtod on the matched string which will only ever convert the
> > bit before the comma.
>
> that's right. Unfortunately, the behavior of strtod(3) depends on the
> locale setting, more precisely the LC_NUMERIC environment variable as
> described in locale(7).
>
> If it was possible to set the locale on a per-thread basis, we might be
> able to make this configurable for the user. I suspect locales can only
> be set on a per-process basis, but I don't know for sure.
 
I'm not convinced that the LC_NUMERIC setting is honored properly as far as the thousands_sep goes for strtod, at least on my Solaris box, or on an Ubuntu box

I suspect a sensible approach would be to query the thousands_sep and then remove that from the string before the strtod (or strtoll etc)??



#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
    char    *ep = NULL;

    double d = strtod(argv[1], &ep);
    printf("Double is %f\n", d);

}

essele at core:~/dev/tmp$ ./go 123
Double is 123.000000
essele at core:~/dev/tmp$ ./go 123.45
Double is 123.450000
essele at core:~/dev/tmp$ ./go 1,234.56
Double is 1.000000
essele at core:~/dev/tmp$ locale -ck thousands_sep
LC_NUMERIC
thousands_sep=","


Regards,

Lee.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20110201/1b1b80f1/attachment.htm>


More information about the collectd mailing list