error using String class to convert a double to a string

i wanted to convert a double to a string i tested several examples online i always get the same error.

the code :

void setup()
{
Serial.begin(9600);

}
void loop()
{
double val =3.2222;
String stringOne = String(val, 3);
Serial.print(stringOne);
}
the errors :

sketch_jun02c.ino: In function ‘void loop()’:
sketch_jun02c.ino:10:36: error: call of overloaded ‘String(double&, int)’ is ambiguous
sketch_jun02c.ino:10:36: note: candidates are:
In file included from /usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:192:0,
from sketch_jun02c.ino:2:
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:70:11: note: String::String(long unsigned int, unsigned char)
explicit String(unsigned long, unsigned char base=10);
^
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:69:11: note: String::String(long int, unsigned char)
explicit String(long, unsigned char base=10);
^
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:68:11: note: String::String(unsigned int, unsigned char)
explicit String(unsigned int, unsigned char base=10);
^
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:67:11: note: String::String(int, unsigned char)
explicit String(int, unsigned char base=10);
^
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:66:11: note: String::String(unsigned char, unsigned char)
explicit String(unsigned char, unsigned char base=10);
^

Use dtostrf() to convert a double to a string, instead.

So the error is that there is no String constructor that takes a double and an int. (Though the error shows a reference to a double which doesn't match your code.)
As written, the code compiles fine for me. Are you using an old version of the IDE? I have v1.8.2.

You could alternatively skip using the String and use instead:

char* dtostrf 	( 	double  	__val,
		signed char  	__width,
		unsigned char  	__prec,
		char *  	__s 
	) 		

The dtostrf() function converts the double value passed in val into an ASCII representationthat will be stored under s. The caller is responsible for providing sufficient storage in s.

Conversion is done in the format "[-]d.ddd". The minimum field width of the output string (including the possible '.' and the possible sign for negative values) is given in width, and prec determines the number of digits after the decimal sign. width is signed value, negative for left adjustment.

The dtostrf() function returns the pointer to the converted string s.

SPaul, i had the same problem when i used dtostrf()
arduarn, Yes i upgraded my Arduino and it works fine.
Thank you guys

kamel:
SPaul, i had the same problem when i used dtostrf()

You used dtostrf and got errors about a String class constructor? That's a pretty neat (impossible) trick. Wanna show us how you did that?

No I i had other errors, and i am sorry I can't show you the errors anymore since i already upgraded my arduino IDE ..

kamel:
No I i had other errors, and i am sorry I can't show you the errors anymore since i already upgraded my arduino IDE ..

OK, I thought you were full of it there. I knew you didn't have the same problem. You had A problem.

You'll have more if you keep using the String class on memory limited systems like microcontrollers.