Trouble using the String constructor to convert a float to a string.

When using the following code:

void setup() {
  // put your setup code here, to run once:
float test = 1.123;

String TestString = String(test, 3);


}

I get the error message:

"call of overloaded 'String(float&, int)' is ambiguous."

As far as I can tell I am using the String constructor exactly as instructed by the Arduino page explaining it. Also I can convert ints to string just fine using the string constructor. The problem only occurs with floats and doubles.

That code compiles fine for me on Arduino 1.6.9

I even added a Serial.print of TestString to make sure it wasn't being optimized away.

void setup() {

Serial.begin(9600);
float test = 1.123;

String TestString = String(test, 3);

Serial.println(TestString);


}
void loop() {
  // put your main code here, to run repeatedly:

}
Sketch uses 4,892 bytes (15%) of program storage space. Maximum is 32,256 bytes.
Global variables use 210 bytes (10%) of dynamic memory, leaving 1,838 bytes for local variables. Maximum is 2,048 bytes.

I am on version 1.8.2 but I doubt that is the problem.

Also the board I am working with is an Intel Edison based PLC from Maxim Integrated which requires its own library. Could that causes issues with the core Arduino features?

gabeseelig:
Also the board I am working with is an Intel Edison based PLC from Maxim Integrated which requires its own library. Could that causes issues with the core Arduino features?

You could have mentioned that you were using some non-standard stuff from the beginning.

I was about to try to download 1.8.2 and try it there, but this hotel has shit for internet service. I'm pretty sure I could get a megabyte of data faster by smoke signals. So we'll have to wait for someone else.

It was the Maxim stuff :frowning:

I just did a clean install of 1.8.2 on my other computer and it compiled.

Do you know of any other way to convert my floats to strings?

You can use dtostrf to convert it into a string (small s).

That’s better anyway. The String class is a memory hog and has a nasty habit of fragmenting memory. That’s OK on a PC with garbage collection and tons of memory. But on a microcontroller it’s best to avoid it and stick with c-style strings (null terminated char arrays) anyway.

Delta_G:
I'm pretty sure I could get a megabyte of data faster by smoke signals.

Use a pigeon :wink: This is now 8 years old but still funny: Pigeon beats Telkom

Hundreds of fans followed Winston's historic flight online, however, many of them had to settle for Twitter updates, as, ironically, their internet connections were too slow to watch the live stream

That's too good.