LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   [C] writing floating point to file- coma instead of dot (http://www.linuxquestions.org/questions/programming-9/%5Bc%5D-writing-floating-point-to-file-coma-instead-of-dot-545498/)

slomek 04-12-2007 01:16 PM

[C] writing floating point to file- coma instead of dot
 
I write number to file like this:
Code:

fprintf(file,"%f",float_number);
And I get e.g. 2,5000 instead of 2.5000. This causes many problems in reading this file by other programs. How to fix this?
I have gcc 4.1.2 and Debian Etch with Polish locales.

tuxdev 04-12-2007 01:52 PM

Switch to "C" locale sometime before this. Or complain to those other program's maintainers that they aren't respecting locale properly. The comma is the Right Thing to do in the Polish locale, so you really shouldn't need to change that.

slomek 04-12-2007 02:14 PM

Quote:

Switch to "C" locale sometime before this.
What do you mean? Or rather: how am I supposed to do this? ;)

jlliagre 04-12-2007 02:43 PM

Quote:

Originally Posted by slomek
What do you mean? Or rather: how am I supposed to do this? ;)

Here is one way:
Code:

export LC_NUMERIC=C

slomek 04-12-2007 03:23 PM

Thanks a lot! ;)
That worked. I must have changed something with my locales. Now its OK.


All times are GMT -5. The time now is 08:09 PM.