I create quite a few ad hoc queries from data tables with large numbers and
the default floating output is a pain to read.

I can get the output format I desire with something elaborate like the
following but this is too much SQL for ad hoc queries.

select
  substr(
    replace(
      substr('     9123456.00',-15,3)||
      substr('     9123456.00',-12,3)||","||
      substr('     9123456.00',-9,3) ||","||
      substr('     9123456.00',-6,6)
    ," ,","  ")
  ,-15,15);
Returns 15 characters as follows:
   9,123,456.00

The bash shell can do this as follows - first without & then with thousand
separator.
$ printf "%15.2f\n" -23456789.12789
   -23456789.13

$ printf "%'15.2f\n" -23456789.12789
 -23,456,789.13

With SQLite the half quote character seems not recognized and no output is
returned:
sqlite> .version
SQLite 3.8.11.1 2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f

sqlite> select printf("%15.2f",-23456789.12789);
   -23456789.13

sqlite> select printf("%'15.2f",-23456789.12789);

sqlite>

A search for an answer suggested the locale setting might be at fault. My
bash output for locale is as follows but I don't if/how this relates to
SQLite.
$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"

Is printf with thousands separator working for anyone?  If so, how?  Any
suggestions?  Thanks for any comments.

Reply via email to