double ambientTemp=44.00;
String yourdatacolumn="yourdata=";
String yourdata;
double yourarduinodata=ambientTemp;
yourdata = yourdatacolumn + yourarduinodata;
I want the output to be string but because of yourarduinodata is double type. Can not convert it to string. Then , I put (String) in front of yourarduinodata, still doesn't let me run throught.
Anyone has any idea about convert double type into string type in arduino sketch?
Another Way To Convert Double To String:
char TempString[10]; // Hold The Convert Data
dtostrf(ambientTemp,2,2,TempString);
// dtostrf( [doubleVar] , [sizeBeforePoint] , [sizeAfterPoint] , [WhereToStoreIt] )
YourArduinoData = String(TempString); // cast it to string from char
Use - String(val, decimalPlaces)
example,
double a = 10.2010;
String SerialData="";
SerialData = String(a,4);
Serial.println(SerialData);
Something like this might work:
String double2string(double n, int ndec) {
String r = "";
int v = n;
r += v; // whole number part
r += '.'; // decimal point
int i;
for (i=0;i<ndec;i++) {
// iterate through each decimal digit for 0..ndec
n -= v;
n *= 10;
v = n;
r += v;
}
return r;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With