diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2003-12-27 19:49:52 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2003-12-27 19:49:52 +0000 |
commit | 52fc07a2a32a001368662e9d54b317f523dd3c5f (patch) | |
tree | aa197186bdc276bccd57b3ee54978e0937835417 /lib/libutil | |
parent | 1b0acfcd62e0ac4cbd57e4b3af595933e3ae04f8 (diff) |
o Do not drop unit when printing -100
o Round negative numbers correctly
o Do not print fractional valus for byte values
ok ian@ henning@
Diffstat (limited to 'lib/libutil')
-rw-r--r-- | lib/libutil/fmt_scaled.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/libutil/fmt_scaled.c b/lib/libutil/fmt_scaled.c index 2785f9e656f..9f75b102432 100644 --- a/lib/libutil/fmt_scaled.c +++ b/lib/libutil/fmt_scaled.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fmt_scaled.c,v 1.1 2003/05/15 01:26:26 ian Exp $ */ +/* $OpenBSD: fmt_scaled.c,v 1.2 2003/12/27 19:49:51 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.1 2003/05/15 01:26:26 ian Exp $"; +static const char ident[] = "$OpenBSD: fmt_scaled.c,v 1.2 2003/12/27 19:49:51 otto Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> @@ -233,15 +233,18 @@ fmt_scaled(long long number, char *result) } } fract = (10 * fract + 512) / 1024; - /* if the result would be >= 10, round main number up */ + /* if the result would be >= 10, round main number */ if (fract == 10) { - number++; + if (number >= 0) + number++; + else + number--; fract = 0; } if (number == 0) strlcpy(result, "0B", FMT_SCALED_STRSIZE); - else if (number > 100 || number < -100) + else if (unit == NONE || number >= 100 || number <= -100) (void)snprintf(result, FMT_SCALED_STRSIZE, "%lld%c", number, scale_chars[unit]); else |