문제

Is there anyway to determine percision at runtime using C commands? there is printf command with dot notation:

printf("%.xf", number);

but x should be fixed before compiling.

도움이 되었습니까?

해결책

Yes, specify an asterisk and provide the precision as a (int) parameter

for (int k = 0; k < 5; k++) printf("%.*f\n", k, 42.0);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top