Hello
is there a way to get from float to string
something like:
string result;
float test = 14535;
test = test/100;
result + = test;
Hello
is there a way to get from float to string
something like:
string result;
float test = 14535;
test = test/100;
result + = test;
Do you mean a String or a string ?
I need it as a string so I can send it over ethernet
string or String? what you propose.
I think that it is string I need to use
string is better but demands more attention.
This works:
char buf[20];//must be large enough ho hold result
void setup(){
Serial.begin(115200);
ftoa(buf, -12.34, 2, ',');
Serial.println(buf);
}//setup()
void loop(){}//loop()
char *ftoa(char *a, double f, int precision, char delim){
long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000};
char *ret = a;
if(f < 0){//negative
f = -f;
*a++ = '-';
}//negative
long i = floor(f);
f -= i;
itoa(i, a, 10);
while (*a != '\0') a++;
*a++ = delim;
itoa(f*p[precision], a, 10);
return ret;
}//ftoa()