From: Yves <yme...@pe...> - 2004-12-30 10:24:52
|
> Hi Yves, > > The problem is not with MySQL but with 'c'. The language translation > introduced a line of code which forces the 'format' to output floating > numbers in local format: > > printf("%f", 0.17) -> "0,17" OK :) > 1. The 'atof' is not locale safe. 0,17 -> 0.00 I suppose that strtof and strtod are not locale safe either. > > 2. The interface to the database. DBMS expects numbers in POSIX format= : > > "INSERT (1,17)" is understood as "INSERT ('1', '17')" > "INSERT ('1,17')" is understood as "INSERT ('1'); > > Users with this version in these countries are therefore sending corrup= t > data to their database. Eg, 'show_load' will be storing only the > integer part of the numbers. THIS IS BAD! I agree :) > 3. The HTML CGI interface. Floating numbers are likely to be > corruption as above. > > > The hack I suggested will fix this: > > setlocale(LC_NUMERIC, "POSIX"); > > But it may be a little too blunt. Correct as a quick fix. > So what do we do? > > 1. Set locale to "POSIX" and loose the localized display? no :) > 2. Set locale to "POSIX" before any SQL, and back to "" afterwards: > > setlocale(LC_NUMERIC, "POSIX"); > sprintf(sql, "INSERT data =3D %f", 0.17); > setlocale(LC_NUMERIC, ""); yes, maybe this is best. > 3. Set the locale to "POSIX" for all the code, accept the presentation. > Here and here only, set back to "": > > setlocale(LC_NUMERIC, ""); > printf("Graph label: %f", 0.17); > setlocale(LC_NUMERIC, "POSIX"); Probably more to print than floats to send to the database. 2 is better. Yves --=20 - Homepage - http://ymettier.free.fr - http://www.logicacmg.com - - GPG key - http://ymettier.free.fr/gpg.txt - - Maitretarot - http://www.nongnu.org/maitretarot/ - - Perfparse - http://perfparse.sf.net/ - |