unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-user@gnu.org
Subject: Re: Formatted output with locale
Date: Mon, 21 Nov 2016 10:31:09 +0100	[thread overview]
Message-ID: <87a8ctxjqa.fsf@gnu.org> (raw)
In-Reply-To: 20161117165324.GA17273@localhost.localdomain

Vladimir Zhbanov <vzhbanov@gmail.com> skribis:

> On Thu, Nov 17, 2016 at 12:02:06PM +0100, Ludovic Courtès wrote:
>> Hi!
>> 
>> dev@famic.de skribis:
>> 
>> > I have problems to get a proper formatting using the (ice-9 format)
>> > module. In my code, I need to deal with monetary figures, but I fail
>> > to get the correct format for my German locale.
>> > Let's say I have one hundred thousand Euros. The correct format to output
>> > this in de_DE.utf-8 would be
>> > 100.000,00 EUR
>> > (with 2 decimals)
>> >
>> > Now I tried:
>> > (setlocale LC_ALL "de_DE.UTF-8")
>> > (use-modules (ice-9 format))
>> > (define a 100000.00)
>> > (format #t "~12,2h EUR~%" a)
>> > (format #t "~,,12$ EUR~%" a)
>> > (format #t "~12,2f EUR~%" a)
>> >
>> > But this is what Guile gives to me:
>> >    100.000,0 EUR
>> >    100000.00 EUR
>> >    100000.00 EUR
>> 
>> It seems to work as advertised for me:
>> 
>> --8<---------------cut here---------------start------------->8---
>> scheme@(guile-user)> ,use(ice-9 i18n)
>> scheme@(guile-user)> (number->locale-string 10000.01 2 (make-locale LC_ALL "fr_FR.utf8"))
>> $13 = "10 000,01"
>> scheme@(guile-user)> (number->locale-string 10000.01 2 (make-locale LC_ALL "de_DE.utf8"))
>> $14 = "10.000,01"
>> scheme@(guile-user)> ,use(ice-9 format)
>> scheme@(guile-user)> (setlocale LC_ALL "de_DE.utf8")
>> $15 = "de_DE.utf8"
>> scheme@(guile-user)> (format #f "~12,2h" 10000.01)
>> $16 = "   10.000,01"
>> --8<---------------cut here---------------end--------------->8---
>
> What does it output if you type
>   (number->locale-string 10000.00 2 (make-locale LC_ALL "fr_FR.utf8"))
>
> that is with two zeros after the point?

I get this:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (number->locale-string 10000.00 2 (make-locale LC_ALL "fr_FR.utf8"))
$1 = "10 000,0"
scheme@(guile-user)> (number->locale-string 10000.00 4  (make-locale LC_ALL "fr_FR.utf8"))              
$2 = "10 000,0"
--8<---------------cut here---------------end--------------->8---

… and that’s definitely a bug.

Could you send it to bug-guile@gnu.org so we keep track of it?

>> That’s on GNU/Linux (glibc 2.24).
>> 
>> Note that number formatting data comes from the C library.  What C
>> library do you use?
>
> My glibc version is 2.19.

It might be responsible for the incorrect thousand and fraction
separators you observe in the de_DE output.  To dig further, you can
check the low-level info provided by ‘nl_langinfo’:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,use(ice-9 i18n)
scheme@(guile-user)> (define l (make-locale LC_ALL "de_DE.utf8"))
scheme@(guile-user)> (locale-digit-grouping l)
$2 = (3 3 . #-1#)
scheme@(guile-user)> (locale-decimal-point l)
$3 = ","
scheme@(guile-user)> (locale-thousands-separator l)
$4 = "."
--8<---------------cut here---------------end--------------->8---

Thanks,
Ludo’.




  reply	other threads:[~2016-11-21  9:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-13 16:56 Formatted output with locale dev
     [not found] ` <CAMvDHVA+TcZg-ak_Nt6vGQW5w4B4KSmEPd3uEziJ0EDXbPp54A@mail.gmail.com>
2016-11-14  6:06   ` Fwd: " Vladimir Zhbanov
2016-11-17 11:02 ` Ludovic Courtès
2016-11-17 16:07   ` Eli Zaretskii
2016-11-17 16:53   ` Vladimir Zhbanov
2016-11-21  9:31     ` Ludovic Courtès [this message]
2016-11-23 12:06       ` Vladimir Zhbanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a8ctxjqa.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).