Skip to content

Commit

Permalink
ADDED: format/2: support ~:D
Browse files Browse the repository at this point in the history
The colon modifier for ``D`` forces the use of Prolog digit grouping
using ``_``.
  • Loading branch information
JanWielemaker committed Nov 16, 2024
1 parent edefcf3 commit f7a501b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion man/builtin.doc
Original file line number Diff line number Diff line change
Expand Up @@ -9758,7 +9758,10 @@ according to the locale of the output stream. See \secref{locale}.
\fmtchar{D}
Same as {\bf d}, but makes large values easier to read by inserting a
comma every three digits left or right of the dot. This is the same
as \verb$~:d$, but using the fixed English locale.
as \verb$~:d$, but using the fixed English locale. If \textbf{D} is
modified using the colon (\verb$~:D$), it uses the Prolog grouping
character \chr{_}. See also setup_prolog_integer_grouping/0. Future
versions may also support line breaks in big integers.

\fmtchar{e}
Output next argument as a floating point number in exponential
Expand Down
12 changes: 9 additions & 3 deletions src/os/pl-fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,15 @@ do_format(IOSTREAM *fd, PL_chars_t *fmt, int argc, term_t argv, Module m)
static char grouping[] = {3,0};

if ( c == 'D' )
{ ltmp.thousands_sep = L",";
ltmp.decimal_point = L".";
ltmp.grouping = grouping;
{ if ( mod_colon )
{ ltmp.thousands_sep = L"_";
ltmp.decimal_point = L".";
ltmp.grouping = grouping;
} else
{ ltmp.thousands_sep = L",";
ltmp.decimal_point = L".";
ltmp.grouping = grouping;
}
l = &ltmp;
} else if ( mod_colon )
{ l = fd->locale;
Expand Down

0 comments on commit f7a501b

Please sign in to comment.