Question. Why use dtostrf() for feeding double-variables to print function?

Hello! I'm trying to optimize my code so I'm using functions to manage all the repetitive printing stuff. I want to write a function able to handle strings and double values as well with extra parameters. I already managed to print but in this topic it's said that is nonsense to feed strings and use float to string conversion. So, I want to ask why I shouldn't use dtostrf() and how I should write the function to handle both variable types?

This is my current code:

void setup() {
  Serial.begin(9600);
  to_serial("Hello world"); //print string
  to_serial(42.42); //print number
}

void loop() {
}

void to_serial(double text, bool param1){ //handle numbers print request
  char text2[5]; //on the same topic is said to be unnecesary to
                 //declare this variable
  return to_serial(dtostrf(text,4,2,text2), param1);
}

void to_serial(char * text, bool param1){ //handle text print request
  Serial.print(text);
  Serial.println();
}

And the output, as expected is:
Hello world
42.50

But, if I comment the first void to serial it doesn't compile:

sketch_sep03a:4:24: error: cannot convert 'double' to 'char*' for argument '1' to 'void to_serial(char*, bool)'

   to_serial(42.42, NULL);

                        ^

exit status 1
cannot convert 'double' to 'char*' for argument '1' to 'void to_serial(char*, bool)'

Is there any other way to handle this? Thanks for your help and time

Delta_G:
If you want to pass that floating point number as a char array then yes you have to dtostrf. But if you just pass a double directly to print it will work as well.

So, is mandatory to take separately double and char pointers or there is another kind of pointer which is able to handle both types? Something like variant type?

Yes, I know print() can handle like everything, but i don't want to write a lot of prints() when I could use functions.

You are pulling in a lot of extra code to do what you want - which does not make any sense. Try a template function instead:

template<typename T> void to_serial(T arg)
{
  Serial.print(arg);
  Serial.println();
}

to_serial(12.34f);
to_serial(1234);

The code above will cause the compiler to create two overload instances of "to_serial"; One that takes a float as an argument and another that takes an int.

Delta_G:
You could write a function template. (Google that if you don't know what it is) but that might seem like some expert level stuff to you.

Thanks! I'll try to use templates