summaryrefslogtreecommitdiff
path: root/lib/libutil/fmt_scaled.c
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2005-03-08 15:35:36 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2005-03-08 15:35:36 +0000
commitbaa53fc9b00a6ca1adf96418924f5f82d37d3c1b (patch)
tree273eca258ec8b11218145c89d1ae32daf2ac2ae3 /lib/libutil/fmt_scaled.c
parent07cd95d987e97a7ece38097c7315c397bbbf2cc9 (diff)
Fix sizing of fraction. ok tom@ deraadt@
Diffstat (limited to 'lib/libutil/fmt_scaled.c')
-rw-r--r--lib/libutil/fmt_scaled.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/lib/libutil/fmt_scaled.c b/lib/libutil/fmt_scaled.c
index c868b4d321f..81edf9a03bb 100644
--- a/lib/libutil/fmt_scaled.c
+++ b/lib/libutil/fmt_scaled.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fmt_scaled.c,v 1.4 2004/09/16 10:56:35 otto Exp $ */
+/* $OpenBSD: fmt_scaled.c,v 1.5 2005/03/08 15:35:35 otto Exp $ */
/*
* Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved.
@@ -37,7 +37,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static const char ident[] = "$OpenBSD: fmt_scaled.c,v 1.4 2004/09/16 10:56:35 otto Exp $";
+static const char ident[] = "$OpenBSD: fmt_scaled.c,v 1.5 2005/03/08 15:35:35 otto Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -222,17 +222,12 @@ fmt_scaled(long long number, char *result)
unit = units[i];
fract = (i == 0) ? 0 : abval % scale_factors[i];
number /= scale_factors[i];
+ if (i > 0)
+ fract /= scale_factors[i - 1];
break;
}
}
- /* scale fraction to one digit (by rounding) - thnx pjanzen */
- for (i = SCALE_LENGTH-1; i > 0; i--) {
- if (fract >= scale_factors[i]) {
- fract /= scale_factors[i];
- break;
- }
- }
fract = (10 * fract + 512) / 1024;
/* if the result would be >= 10, round main number */
if (fract == 10) {