As stated previously on this thread, before @J-M-L hijacked the comment to another thread.
dtostrf() is prone to buffer overflow, because the 'width' arg is the MINIMUM width not the maximum
A simple replacement is the print( ) function from SafeString library which protects against buffer overflows
char output; double d = 33.55; cSFA(sfOutput,output); // wrap in a safestring sfOutput.print(d, 5); // print with 5 decs
If the result would overflow, an empy SafeString results and an error flag and detailed error message is available.
The direct use of dtostrf( ) will just crash your sketch in that case.
My SafeString library also has a modified print( ), the outputs a FIXED limited width string and reduces the number of decimal points when the number would exceed the FIXED width
This method can also be used for ints and longs by passing 0 for the decs.
d- the double to convert to text
decs- the preferred number of decimial places to output(limited to <7). This will be reduced automatically to fit the fixed width.
width- fixed width the output is to padded/limited to
forceSign- optional, defaults to false, if true the + sign is added for +ve numbers
dtostrf is used inside this print, but with the necessary checks on the size of the number and the necessary restrictions on number of decimal points printed and with the correct char[ ] size so that it does not overflow.