"Yi, EungJun" <semtlenori@xxxxxxxxx> writes: > I think it is possible like this: > > num_langs += 1; /* for '*' */ > decimal_places = 1 + (num_langs > 10) + (num_langs > 100); > snprintf(q_format, sizeof(q_format), "; q=%%.%df", decimal_places); > for (q_precision = 1.0; decimal_places-- > 0;) q_precision /= 10; > > Does this one look better than before? I'm not sure which one is better. > > ps. The last line can be simpler by using pow() but I'm not sure it is > okay to include math.h. If you do not want floating point (and I think we tend to avoid it when we do not need it), you can realize that in your use of "0.1" and "0.01" and "0.001" there is nothing fundamentally floating-point; you can measure how many digits below the two-byte string zero-dot you would want upfront (by counting num_langs), and show an integer counter zero-padded to the left to that width. That would avoid having to even worry about a possible funny case where subtracting 0.01 ten times from 0.1 may not yield zero (or the result of subtracting nine times may not reach 0.01) due to rounding errors accumulating, which was the first thing that came to my mind when I saw your loop. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html