Convert comma-point - , to .

good night

I have a string that receives a value, with comma eg 11,222

How do I convert a string to comma point?

I'm trying to convert the string to float, however because of the comma does not handle values ​​before the comma

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
float to_float(const std::string& str)
{
   std::istringstream is(str) ;
   float result;
   result = ::strtod(str.c_str(), 0);
   is >> result;
   return result ;
}




float var4 = to_float(var3);

Last edited on
I just have to ask. What the heck is "virtgula"?
try
1
2
3
std::istringstream is(str);
is.imbue(std::locale(""));
is >> result;

that's the intended usage ( but it may not work on some system configurations)
@helios: +18
Maybe I'm being too puritan, +14
Last edited on
Resolvido, usei
std::replace(var3.begin(), var3.end(), ',', '.');
Topic archived. No new replies allowed.