Bug 5529 - Use commas in displayed numbers
Summary: Use commas in displayed numbers
Alias: None
Product: rsync
Classification: Unclassified
Component: core (show other bugs)
Version: 3.1.0
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---
Assignee: Wayne Davison
QA Contact: Rsync QA Contact
Depends on:
Reported: 2008-06-09 17:02 UTC by Dave Yost
Modified: 2008-09-06 09:52 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Dave Yost 2008-06-09 17:02:25 UTC
   135227644  44%   48.07kB/s    0:58:07

should be

   135,227,644  44%   48.07kB/s    0:58:07

How many hours of our life to we waste painstakingly counting digits to see if a big number is 13MB or 135MB or 1.3GB?  We can thank the fact that printf didn't offer to insert commas for that.
Comment 1 Simo Sorce 2008-06-09 17:12:32 UTC
The problem is also that the separator is locale dependent, in some locales the separators "." and "," has the inverse meaning.

That is: . is the thousands separator and , is the decimal part separator.

If you need to add separators you must do it in a locale dependent way.
Comment 2 Jamie Lokier 2008-06-10 06:39:06 UTC
Fwiw, printf() _does_ insert commas if you ask for it - as a GNU extension.  So suitable for GNU/Linux and some other environments.

Write something like %'lld - the apostrophe modifier character asks for 'thousands grouping character'.

It is locale-dependent.  Some locales use '.' to separate thousands, some have a different number of digits per group, and some don't do grouping.

To do it somewhat portably, use localeconv(), nl_langinfo() and/or strfmon().  The GNU libc manual explains (among other places).
Comment 3 Wayne Davison 2008-06-14 12:27:15 UTC
You can use the -h (--human-readable) option to ask rsync to display sizes with suffixes, so you'd see 135.23M instead of 135227644.  An option to insert commas (or periods) would be nice, though, and easy to do in the human_num() routine that is already handling the numbers.  e.g., a version with commas hard-wired:

--- a/util.c
+++ b/util.c
@@ -1197,6 +1197,7 @@ char *human_num(int64 num)
        static char bufs[4][128]; /* more than enough room */
        static unsigned int n;
        char *s;
+       int pos;
        n = (n + 1) % (sizeof bufs / sizeof bufs[0]);
@@ -1225,7 +1226,9 @@ char *human_num(int64 num)
        if (!num)
                *--s = '0';
-       while (num) {
+       for (pos = 0; num; pos++) {
+               if (pos && (pos % 3) == 0)
+                       *--s = ',';
                *--s = (char)(num % 10) + '0';
                num /= 10;

Other changes would be needed to make room for the extra width in the progress output, but I'll consider this for the future.
Comment 4 Wayne Davison 2008-09-06 09:52:01 UTC
The 3.1.0dev source now outputs numbers in this more readable fashion (with a way to turn it off, as desired).