summaryrefslogtreecommitdiff
path: root/doc/ref/misc-modules.texi
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-02-03 16:35:06 +0100
committerLudovic Courtès <ludo@gnu.org>2012-02-03 16:35:06 +0100
commitafd08fdf87caa499abf3423c663eb44be57cceb9 (patch)
treef461305f64808a40ad3a5120b33d54dd8f57a55c /doc/ref/misc-modules.texi
parentc76fdf69a833378ce18228d242e926009df9add1 (diff)
downloadguile-afd08fdf87caa499abf3423c663eb44be57cceb9.tar.gz
format: Add specifier ~h for localized number output.
* doc/ref/misc-modules.texi (Formatted Output): Document ~h. Recommend use of ~h instead of ~:d. * module/ice-9/format.scm (format): Add support for ~h. * test-suite/tests/format.test ("~h localized number"): New test prefix. * test-suite/tests/i18n.test (%american-english-locale-name, %american-english-locale): New variables. (under-american-english-locale-or-unresolved): New procedure. ("format ~h"): New test prefix.
Diffstat (limited to 'doc/ref/misc-modules.texi')
-rw-r--r--doc/ref/misc-modules.texi29
1 files changed, 27 insertions, 2 deletions
diff --git a/doc/ref/misc-modules.texi b/doc/ref/misc-modules.texi
index 2a6630cd6..022b7cb5b 100644
--- a/doc/ref/misc-modules.texi
+++ b/doc/ref/misc-modules.texi
@@ -269,7 +269,7 @@ Integer. Parameters: @var{minwidth}, @var{padchar}, @var{commachar},
@var{commawidth}.
Output an integer argument as a decimal, hexadecimal, octal or binary
-integer (respectively).
+integer (respectively), in a locale-independent way.
@example
(format #t "~d" 123) @print{} 123
@@ -297,7 +297,9 @@ minimum), it's padded on the left with the @var{padchar} parameter
@end example
@nicode{~:d} adds commas (or the @var{commachar} parameter) every
-three digits (or the @var{commawidth} parameter many).
+three digits (or the @var{commawidth} parameter many). However, when
+your intent is to write numbers in a way that follows typographical
+conventions, using @nicode{~h} is recommended.
@example
(format #t "~:d" 1234567) @print{} 1,234,567
@@ -404,6 +406,29 @@ printed instead of the value.
(format #t "~5,,,'xf" 12345) @print{} xxxxx
@end example
+@item @nicode{~h}
+Localized number@footnote{The @nicode{~h} format specifier first
+appeared in Guile version 2.0.6.}. Parameters: @var{width},
+@var{decimals}, @var{padchar}.
+
+Like @nicode{~f}, output an exact or floating point number, but do so
+according to the current locale, or according to the given locale object
+when the @code{:} modifier is used (@pxref{Number Input and Output,
+@code{number->locale-string}}).
+
+@example
+(format #t "~h" 12345.5678) ; with "C" as the current locale
+@print{} 12345.5678
+
+(format #t "~14,,'*:h" 12345.5678
+ (make-locale LC_ALL "en_US"))
+@print{} ***12,345.5678
+
+(format #t "~,2:h" 12345.5678
+ (make-locale LC_NUMERIC "fr_FR"))
+@print{} 12 345,56
+@end example
+
@item @nicode{~e}
Exponential float. Parameters: @var{width}, @var{mantdigits},
@var{expdigits}, @var{intdigits}, @var{overflowchar}, @var{padchar},