double to char* conversion. Weird results from dtostrf Here’s the code:

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

    double lat = 1111.11;
    double lon = 4444.44;

    const byte len{10};

    char sLat[len];
    char sLon[len];

    dtostrf(lat, len, 2, sLat);
    Serial.println(sLat);

    Serial.println("---");

    dtostrf(lon, len, 2, sLon);
    Serial.println(sLon);
    Serial.println(sLat); // &lt;-- prints nothing!

    Serial.println("---");

    dtostrf(lat, len, 2, sLat);
    Serial.println(sLat);
    Serial.println(sLon); // &lt;-- prints nothing!
}

void loop()
{
}


Here’s the output:

   1111.11
---
   4444.44

---
   1111.11
   4444.44   1111.11


As you see. Every next call for dtostrf ruins the previous results, in a weird way.

What’s the problem?
If len is the text array size, you need space there for the terminating '\0'.
So the second paramater to dtostrf has to be smaller than len.