Specific formatting of floats and converting them to an array of chars
Normally sprintf() would be the solution - however the sprintf() in the AVR LIBC is a cutdown version with no floating point support.

Instead you have to use dtostrf() to get the job done:

dtostrf(val, 6, 4, buffer);


The numbers there are the maximum width of the string (note: you need to take into account any minus sign in that value), and the number of decimal places (6,4 would give you room for "0.0000" but not "-0.0000"). Make sure your buffer is bigger by one byte than your text, since you have to have the trailing NULL character in there to terminate it.

Another (nasty) way would be to go via String (although I would never recommend using String for anything, ever):

String s(val, 4);
const char *buf = s.c_str(); // this points to the internal char buffer.