I found interesting format for printing nonterminated fixed length strings like this:
char newstr[40] = {0};
sprintf(newstr,"%.*s", sizeof(mystr), mystr);
So I think maybe is there a way under printf command for printing a float number…
"%8.2f"
to have ability to choose number of decimals with integer number.
Something like this:
sprintf(mystr, "%d %f", numberofdecimals, floatnumbervalue)
Best Answer
You can also use
".*"
with floating points, see also http://www.cplusplus.com/reference/cstdio/printf/ (refers to C++, but the format specifiers are similar)For example:
Output: