Same code different boards does not work (float to char string conversion)

So I have these 2 LoRa enabled boards: The Feather M0 and the Feather 32u4

On the M0 I use the following code to convert my battery life to a string:

float battery = analogRead(A7);
battery *= 2;
battery *= 3.3;
battery /= 1024;

char battery_c[5];

String temp = String (battery);
temp.toCharArray(battery_c,5);

Serial.println(battery_c);

This outputs the float as a char string.

The same code on the 32u4 however, produces a "?".

String temp = String(3) works, String temp = String(3.12) does not work.

So I decided to try the dtostrf method:

float battery = analogRead(A7);
battery *= 2;
battery *= 3.3;
battery /= 1024;

char battery_c[5];

dtostrf(battery, 4, 2, battery_c);

Serial.println(battery_c);

Yields a "?" again. I know that sprintf does not work with float values on arduino. dtostrf did not work at all on the M0 (not declared in this scope error) and on the 32u4 none of the methods worked.

Now I am wondering why this happens?

The pinout diagram for the 32u4 is confusing, but looking at a picture of the PCB, I only see A0 through A5, which all the description mentions too. Try another analog pin.

You have specified the minimum field width in dtosrtf() and allocated sufficient space for ONLY that number of characters. If the actual output field width is larger, the code will overwrite memory you don't own, with unpredictable results.

char battery_c[5];

dtostrf(battery, 4, 2, battery_c);

@wildbill

Serial.println(battery) gives me back the float value, so the Analog pin should be correct. I tried A9 though, same issue. So I think the problem is the conversion somehow

@jremington

I am aware of memory issues, i tried to allocate up to 128 and it still didn't work.

I really wonder why the M0 board does it but the 32u4 doesnt.