Skip to main content
Arduino

Return to Question

edited tags
Link
user31481
user31481
Source Link
Ryan
  • 3
  • 2

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 allawys 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);
 ^

AltStyle によって変換されたページ (->オリジナル) /