Hello Guilers!
Our beloved ‘format’ now supports locale-dependent number output, using
the new ~h format specifier:
~h
Localized number(1). Parameters: WIDTH, DECIMALS, PADCHAR.
Like ~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 `:' modifier is used (*note
`number->locale-string': Number Input and Output.).
(format #t "~h" 12345.5678) ; with "C" as the current locale
-| 12345.5678
(format #t "~14,,'*:h" 12345.5678
(make-locale LC_ALL "en_US"))
-| ***12,345.5678
(format #t "~,2:h" 12345.5678
(make-locale LC_NUMERIC "fr_FR"))
-| 12 345,56
The difference with ~f is that it doesn’t have the SCALE and
OVERFLOWCHAR parameters (it would be doable but seems overkill to me),
and it supports the ‘:’ modifier to specify a locale object.
I would appreciate comments on the interface, since it will basically be
around forever.
Also, if you’re aware of other Schemes that have a ‘format’-like
procedure that supports localized number output, it may be a good idea
to try to choose an interface close to theirs (like using a whatever
letter they use instead of ~h.)
Thanks!
Ludo’.