From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.user Subject: Re: Formatted output with locale Date: Mon, 21 Nov 2016 10:31:09 +0100 Message-ID: <87a8ctxjqa.fsf@gnu.org> References: <20161113165638.GA23086@remote.famic.de> <87inrm5pzl.fsf@gnu.org> <20161117165324.GA17273@localhost.localdomain> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1479720711 31005 195.159.176.226 (21 Nov 2016 09:31:51 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 21 Nov 2016 09:31:51 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Nov 21 10:31:46 2016 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c8kx0-0006rG-3v for guile-user@m.gmane.org; Mon, 21 Nov 2016 10:31:46 +0100 Original-Received: from localhost ([::1]:48274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8kx2-0004H8-3f for guile-user@m.gmane.org; Mon, 21 Nov 2016 04:31:48 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8kwd-0004Gn-Fi for guile-user@gnu.org; Mon, 21 Nov 2016 04:31:24 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c8kwa-000163-9l for guile-user@gnu.org; Mon, 21 Nov 2016 04:31:23 -0500 Original-Received: from [195.159.176.226] (port=59273 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c8kwa-00015b-2s for guile-user@gnu.org; Mon, 21 Nov 2016 04:31:20 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1c8kwS-00023f-T8 for guile-user@gnu.org; Mon, 21 Nov 2016 10:31:12 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 85 Original-X-Complaints-To: usenet@blaine.gmane.org X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 1 Frimaire an 225 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-unknown-linux-gnu Cancel-Lock: sha1:sZ8cplfcp8ML7K0A4uV5Ll74aT4= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:12993 Archived-At: Vladimir Zhbanov 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’.