How to safely and reasonably convert a float or double to string or char array?

alirezasafdari:
Let's say a sensor connection come loose and the ADC reading drops to a level it would never happen if the sensor was attached to it. And for some reasons a constant is divided by this float variable coming out of sensor. Then your dtostrf is going to mess the whole memory. Put it in a expensive project with mechanical stuff involved and then things may not look that good.

You are misunderstanding what a float or double variable can or cannot do. Even if the number gets as large as 35 9's in a row, a float variable can't represent that exactly. It's only going to be able to do 6 or maybe 7 digits of precision. So you wouldn't want to print out all 35 digits. They wouldn't be right anyway. Just print out the 6 digits you know are good. So represent it as 9.99999E34. With dtostrf you get to specify how many digits to display. So you'll know the maximum possible width of the string it produces and can plan your array accordingly. Trying to capture all those digits is just a total waste of your time and effort.