Setting count of decimal digits in printf at runtime in C language
问题 I have a number: m which is given by the user as parameter. For example: m = 5 or m = 7 I do not know this at run-time. I then compute an integral and save it to a variable: answer . I want to print answer with m decimals digits. How can I do this? I tried this one: printf("answer = %(%.mf)d ", answer , m); It's wrong ,I know ,but how can I solve it? 回答1: If you have a variable with a value, say: double val = 3.234003467; You could print out to the 2nd decimal place for example using: printf(