Double value to String

Hi Everyone,

I have a code in which I use two variable whose type is double. when I use the following code to print the double variable it works perfectly.

Serial.println(A, 6);

The out put is like 47.913459. But when I use the following code it just return the 47.91.

Serial.println(A);

The question is that how can I convert these variable to string with the full precision.

Many thanks in advance.
Mahdiyar

If you want to print with more than 2 places use the print(float, places) form.

Serial.print(pi, 5);

If you want to change a float to a string use dtostrf().

groundFungus:
If you want to print with more than 2 places use the print(float, places) form.

Serial.print(pi, 5);

If you want to change a float to a string use dtostrf().

Thank you.

I've tried it it is not working always fine. I have used it in the following code and the output is 39.123455 while it should be 39.123456.

void setup()
{
  Serial.begin(9600);
  
  double floatVal=39.123456;
  char charVal[15];               //temporarily holds data from vals 
  String stringVal = "";     //data on buff is copied to this string
  
  dtostrf(floatVal, 9, 6, charVal);  //4 is mininum width, 4 is precision; float value is copied onto buff
  //display character array
  stringVal = String(charVal);  
  Serial.print("stringVal: ");Serial.println(stringVal); //display string
}
void loop()
{
  
}

I refer you to the reference on the float data type for Arduino. The float data type limited in precision.