Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/gen Don't ever add a ".0" to a single digit number.



details:   https://anonhg.NetBSD.org/src/rev/38d951ba3f6d
branches:  trunk
changeset: 556741:38d951ba3f6d
user:      simonb <simonb%NetBSD.org@localhost>
date:      Fri Dec 26 11:30:36 2003 +0000

description:
Don't ever add a ".0" to a single digit number.

XXX: Should (for example) 1024 be 1.0K or 1K when the HN_DECIMAL flag
     is passed?  Should there be a separate option that says "use the
     HN_DECIMAL behaviour unless we are exactly equal to the suffix"?

diffstat:

 lib/libc/gen/humanize_number.c |  31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)

diffs (52 lines):

diff -r c7c17bb94dfe -r 38d951ba3f6d lib/libc/gen/humanize_number.c
--- a/lib/libc/gen/humanize_number.c    Fri Dec 26 11:23:44 2003 +0000
+++ b/lib/libc/gen/humanize_number.c    Fri Dec 26 11:30:36 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: humanize_number.c,v 1.4 2002/11/11 18:00:43 thorpej Exp $      */
+/*     $NetBSD: humanize_number.c,v 1.5 2003/12/26 11:30:36 simonb Exp $       */
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 #ifndef __lint
 __COPYRIGHT("@(#) Copyright (c) 2002\n\
        The NetBSD Foundation, inc. All rights reserved.\n");
-__RCSID("$NetBSD: humanize_number.c,v 1.4 2002/11/11 18:00:43 thorpej Exp $");
+__RCSID("$NetBSD: humanize_number.c,v 1.5 2003/12/26 11:30:36 simonb Exp $");
 #endif /* !__lint */
 
 #include <assert.h>
@@ -133,15 +133,24 @@
                        s1++;
                        s2 = 0;
                }
-               r = snprintf(buf, len, "%lld%s%lld%s%c%s",
-                   /* LONGLONG */
-                   (long long)(sign * s1),
-                   localeconv()->decimal_point,
-                   /* LONGLONG */
-                   (long long)s2,
-                   (i == 0 && !(flags & HN_B)) || flags & HN_NOSPACE ?
-                   "" : " ", (i == 0 && (flags & HN_B)) ? 'B' :
-                   prefixes[i], suffix);
+               if (s1 < 10 && i == 0)
+                       /* Don't ever use .0 for a number less than 10. */
+                       r = snprintf(buf, len, "%lld%s%c%s",
+                           /* LONGLONG */
+                           (long long)(sign * s1),
+                           (i == 0 && !(flags & HN_B)) || flags & HN_NOSPACE ?
+                           "" : " ", (i == 0 && (flags & HN_B)) ? 'B' :
+                           prefixes[i], suffix);
+               else
+                       r = snprintf(buf, len, "%lld%s%lld%s%c%s",
+                           /* LONGLONG */
+                           (long long)(sign * s1),
+                           localeconv()->decimal_point,
+                           /* LONGLONG */
+                           (long long)s2,
+                           (i == 0 && !(flags & HN_B)) || flags & HN_NOSPACE ?
+                           "" : " ", (i == 0 && (flags & HN_B)) ? 'B' :
+                           prefixes[i], suffix);
 
        } else
                r = snprintf(buf, len, "%lld%s%c%s",



Home | Main Index | Thread Index | Old Index