- do {
- sprintf(tmp, "%u", modulo);
- if (strlen(tmp) <= decimals - 1)
- break;
-
- modulo = (modulo + 9) / 10;
- } while (1);
+ /*
+ * Fill in everything and return the result.
+ */
+ assert(maxlen - strlen(tmp) - 1 > 0);
+ assert(modulo < thousand[!!pow2]);
+ sprintf(fmt, "%%.%df", (int)(maxlen - strlen(tmp) - 1));
+ sprintf(tmp, fmt, (double)modulo / (double)thousand[!!pow2]);