Browse Source

Fix sizing of fraction. ok tom@ deraadt@

OPENBSD_3_7
otto 20 years ago
parent
commit
7176d2991e
1 changed files with 4 additions and 9 deletions
  1. +4
    -9
      src/lib/libutil/fmt_scaled.c

+ 4
- 9
src/lib/libutil/fmt_scaled.c View File

@ -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) {


Loading…
Cancel
Save