summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2005-03-09 09:27:57 +0000
committerotto <otto@openbsd.org>2005-03-09 09:27:57 +0000
commit9ba968b719a22ce33d4f5b5e72bc9887dc5097fc (patch)
treea10e42256aec7903d1f4fc4049b5e66056d143cc /lib/libutil
parentthe man page was completely revised by others, remove myself as its author. (diff)
downloadwireguard-openbsd-9ba968b719a22ce33d4f5b5e72bc9887dc5097fc.tar.xz
wireguard-openbsd-9ba968b719a22ce33d4f5b5e72bc9887dc5097fc.zip
Fix rounding of fractionless numbers. ok tom@ miod@
Diffstat (limited to 'lib/libutil')
-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]);