(Solved) trouble converting float to char[]

Hello, I'm trying to convert a float from a DHT22 sensor to a char[] for MQTT publishing on an ESP8266. I've tried sprintf and snprintf, but haven't been able to print the actual float value. I thought I'm using the character reference correctly, but maybe someone can tell me? I see, literally, the "%.1f".

I'm seeing the same thing on serial monitor as I'm getting when subscribed to the MQTT topic.

char msg[50];

void loop() {

client.loop();

delay(400);

float temp = dht.readTemperature();

Serial.print("\t\t"); Serial.print(temp, 1); Serial.print("\t\t");

//snprintf (msg, 50, "%.1f", temp); // just get "%.1f" //sprintf (msg, "%.1f", temp); // just get "%.1f"

Serial.print("Publish message: "); Serial.println(msg); //I'm seeing the same thing in serial monitor as I am in MQTT client.publish("temp", msg); //MQTT publish

delay (4000); }

EDIT: integers and %ld works like it should!

Look up dtostrf() to convert floats to chat array. Arduino does not support floats with sprintf.

dtostrf()

ah, thanks!

@arusr, I answered your last question, but you edited as I was typing and removed the question, so I removed the answer.