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