From 7176d2991efc5bbc5e6313f81c6178457e607363 Mon Sep 17 00:00:00 2001 From: otto <> Date: Tue, 8 Mar 2005 15:35:35 +0000 Subject: [PATCH] Fix sizing of fraction. ok tom@ deraadt@ --- src/lib/libutil/fmt_scaled.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/lib/libutil/fmt_scaled.c b/src/lib/libutil/fmt_scaled.c index c868b4d3..81edf9a0 100644 --- a/src/lib/libutil/fmt_scaled.c +++ b/src/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 @@ -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) {