string inttostr(int integer) {
ostringstream MyStream;
MyStream<<integer<<flush;
return (MyStream.str());
}
int strtoint(string String) { //can be modified to make better, but this should work for simple stuff
int a;
stringstream stream;
for(int b = 0; b < String.size(); b++) {
if(!isdigit(String.at(b))) {
String.erase(b, 1);
}
}
stream<<String<<flush;
stream>>a;
return a;
}
I'm using a method similar to firedraco's to convert a string to a float, perform calculations with it, then convert my float result to a string that i display in an Edit Control.
Does anyone know a function that could limit the number of decimal points of my float result to 3 before i convert it to a string to be displayed in the Edit Control?
You need to set the stream to fixed notation then set the precision to 3.
This will mean you always get 3 decimal places - so 0.5 would display as 0.500.
See http://www.cplusplus.com/reference/iostream/ostringstream/ for docs on the syntax for setting precision and fixed notation.