i'm writing a double value to a file. The numeric value is written with a point as a decimal separator. I would like to use a comma. How i can do that?
Asked
Active
Viewed 1,883 times
2
-
Please post your code, without code to reference it's hard to make suggestions – Sam Post Feb 09 '10 at 01:11
3 Answers
3
The usual way is to use a locale with the decimal separator set to the comma. If your machine is configured for that generally, you can probably just use the nameless locale for it:
std::cout.imbue(std::locale(""));
std::cout << 12345.67;

Jerry Coffin
- 476,176
- 80
- 629
- 1,111
2
You can find the answer in an earlier question This basically changes the locale used by the streams you are using.

Community
- 1
- 1

Michael Anderson
- 70,661
- 7
- 134
- 187
-1
I think in the library cmath
there is a function called modf which takes a float or double, and a pointer to an float or double, and returns an integer.
double intPart; double fractPart; fractPart = modf(doubleValue, &intPart);
So you pass in the double value, it returns the decimal part as an integer, and the integer value is stored in the pointer you passed in.
You could then write these to file however you want, with a comma in the middle or whatever, just write it as two separate numbers. float or double

Craig
- 1,199
- 1
- 13
- 27