In that case, then use * for width and .* for precision so you can specify them on the fly
i.e.
sprintf(txt, "%*.*f", width, precision, val);
computing width and precision should be easy enough.
I think Arduino's printf doesn't support float formatting to save space by default, but there is a way to enable that functionality.