summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2005-03-09 09:27:58 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2005-03-09 09:27:58 +0000
commit4feb11683b16df31c0c7d1a8cdc917ae4411e7da (patch)
tree0d4a74eff0973f67361e5535bc80ce9a2065567d /lib
parentea9ff75adbbf739fc1317c9a509c221086854c3d (diff)
Fix rounding of fractionless numbers. ok tom@ miod@
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/fmt_scaled.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/libutil/fmt_scaled.c b/lib/libutil/fmt_scaled.c
index 81edf9a03bb..c73d6286de8 100644
--- a/lib/libutil/fmt_scaled.c
+++ b/lib/libutil/fmt_scaled.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fmt_scaled.c,v 1.5 2005/03/08 15:35:35 otto Exp $ */
+/* $OpenBSD: fmt_scaled.c,v 1.6 2005/03/09 09:27:57 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.5 2005/03/08 15:35:35 otto Exp $";
+static const char ident[] = "$OpenBSD: fmt_scaled.c,v 1.6 2005/03/09 09:27:57 otto Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -240,10 +240,16 @@ fmt_scaled(long long number, char *result)
if (number == 0)
strlcpy(result, "0B", FMT_SCALED_STRSIZE);
- else if (unit == NONE || number >= 100 || number <= -100)
+ else if (unit == NONE || number >= 100 || number <= -100) {
+ if (fract >= 5) {
+ if (number >= 0)
+ number++;
+ else
+ number--;
+ }
(void)snprintf(result, FMT_SCALED_STRSIZE, "%lld%c",
number, scale_chars[unit]);
- else
+ } else
(void)snprintf(result, FMT_SCALED_STRSIZE, "%lld.%1lld%c",
number, fract, scale_chars[unit]);