commit 7416024725de94f0368c952bfb9d83e46ae87ee9
parent ad68edeea77f6ba2ae839685cd449597b7ee5467
Author: Claudio Alessi <smoppy@gmail.com>
Date: Sun, 29 May 2022 18:28:37 +0200
Simplify time_print()
Diffstat:
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/snore.c b/snore.c
@@ -89,16 +89,10 @@ void
time_print(double tm) {
double piece;
int i;
- char buf[10], *p;
for(i = LENGTH(symbols) - 1; i >= 0; --i) {
piece = tm / symbols[i].mult;
- snprintf(buf, sizeof buf, "%09f", piece);
- p = strrchr(buf, '.');
- if(symbols[i].precision)
- p += 1 + symbols[i].precision; /* truncate */
- *p = '\0';
- printf("%s%c%s", buf, symbols[i].sym, i ? " " : "");
+ printf("%.*f%c%s", symbols[i].precision, piece, symbols[i].sym, i ? " " : "");
tm -= (int)piece * symbols[i].mult;
}
}