Yes you can do it. You must use an asterisk * as the field width and .* As the precision. Then you need to provide arguments that carry values. Sort of
sprintf(myNumber,"%*.*lf",A,B,a);
Note: A and B must be of type int . From the C11 standard, chapter §7.21.6.1, fprintf() function
... the width of the field, or the accuracy, or both, can be indicated by an asterisk. In this case, the int argument provides the field width or precision. Arguments indicating the width of the field, or precision, or both, must be displayed (in that order) before converting the argument (if any). The negative field width argument is taken as the - flag, followed by the positive field width. The negative precision argument is accepted as if the precision were omitted.
source share