سؤال

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