From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Vladimir Zhbanov Newsgroups: gmane.lisp.guile.user Subject: Fwd: Formatted output with locale Date: Mon, 14 Nov 2016 09:06:08 +0300 Message-ID: References: <20161113165638.GA23086@remote.famic.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1479103640 10141 195.159.176.226 (14 Nov 2016 06:07:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 14 Nov 2016 06:07:20 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Nov 14 07:07:15 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 1c6APs-0007E9-G9 for guile-user@m.gmane.org; Mon, 14 Nov 2016 07:06:52 +0100 Original-Received: from localhost ([::1]:36372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6APv-0002CB-HR for guile-user@m.gmane.org; Mon, 14 Nov 2016 01:06:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6APZ-0002C4-0n for guile-user@gnu.org; Mon, 14 Nov 2016 01:06:33 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6APX-000421-Rg for guile-user@gnu.org; Mon, 14 Nov 2016 01:06:33 -0500 Original-Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:38660) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c6APX-00040I-K2 for guile-user@gnu.org; Mon, 14 Nov 2016 01:06:31 -0500 Original-Received: by mail-wm0-x22c.google.com with SMTP id f82so78643380wmf.1 for ; Sun, 13 Nov 2016 22:06:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=aRhlZRkYR8+0Pf2ixcd6r/n96Y29RKPzh/K9o0ErgI8=; b=Y76AzPSuhVX/mCCxCBNTfLXurK5cJ91YW+HY0MokJDQBtTl29PvE55zJz3giOjo3am ll/85ORpbfvuK9ezzYmME5mVavkVXOlsfrpNagZCIDJgGy/goj1DGxgB9jWJX+fJMP6K tLUlHXtbdbXl2P6Q9pxMcAZKrKcPq3/kmEOpq5TmZqcqnGy9iO6A/Lap0wOGPvbjjN9i gsupLSsYeEzaLXo85is3hQPKrGsgVT1+V28jR9IIEtqPvqAJ05IAgQP3A9bH7eZHmGeS E4GXC8mdCF1WGIukbLAJ0SmNVmhwBuvEnh9xaFDyAEv9PoLYUeBeeC8erToTsmLcnbYW 0J5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=aRhlZRkYR8+0Pf2ixcd6r/n96Y29RKPzh/K9o0ErgI8=; b=jNVASd+KwkEITUONACww5u7QmKsydL5PhwRyo7qpo9OlrYttAaD9cfi0b+tw6RMl3D ITnWPp6Qj3cHSUDUgUUbYyHo/RJkddR0OGk3SmrVjyhD/3HRGbBZmsKzYXVk/UMgwFVr wDhYhHQdBSUw4NWwKyqGuxbkvfQQkeq5qZm/TO7MTEYjDL0LBYf1aKxHAIA7Kt1Xh0rL WlASyYibtPFb6h6beYhUpffQgu8j+x29n6fr1zhfMVrubIshTPySn7E2P06Ur1edHdPe nHxbUTutS143U1KKXTg+T2MEzwmfnhjzOTqW+LF3B2BQ9txCnkAHmV/ebM7cat1xeJsc D1Rw== X-Gm-Message-State: ABUngvcvi7nxiXwF+tFyJBo5pVbDXRbHNnEqi41C+tLkB2E554HhoHBmFPTE2GgJrpQq87Q6VwBupxKvRgUdUA== X-Received: by 10.194.29.231 with SMTP id n7mr18117819wjh.104.1479103569081; Sun, 13 Nov 2016 22:06:09 -0800 (PST) Original-Received: by 10.28.63.77 with HTTP; Sun, 13 Nov 2016 22:06:08 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22c 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:12987 Archived-At: Martin, I'm sorry for the private reply, my fault :-( Forward to the list. ---------- Forwarded message ---------- From: Vladimir Zhbanov Date: Mon, 14 Nov 2016 09:03:19 +0300 Subject: Re: Formatted output with locale To: dev@famic.de Hi Martin, On 11/13/16, dev@famic.de wrote: > Hi there, > 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 > > None is correct. What did I miss? > -Martin Looking at the `format' code for option `h' I see the procedure `number->locale-string' is used. OK, let's do some experiments: scheme@(guile-user)> (setlocale LC_ALL) $2 = "ru_RU.UTF-8" scheme@(guile-user)> ,use (ice-9 i18n) scheme@(guile-user)> (number->locale-string 10.0 5) $3 = "10,0" scheme@(guile-user)> (number->locale-string .00003 2) $4 = "3,0e" scheme@(guile-user)> (number->locale-string .00003 1) $5 = "3,0" scheme@(guile-user)> (number->locale-string .00003 3) $6 = "3,0e-" scheme@(guile-user)> (number->locale-string .0 3) $7 = "-0,0" scheme@(guile-user)> (number->locale-string .0 10) $8 = "-0,0" scheme@(guile-user)> (number->locale-string .0 1) $9 = "-0,0" Now for the procedure monetary-amount->locale-string: scheme@(guile-user)> (monetary-amount->locale-string .0 #t) $10 = "-0.0 RUB " scheme@(guile-user)> (monetary-amount->locale-string 100000.0 #t) $11 = "100\xa0000.0 RUB " scheme@(guile-user)> (monetary-amount->locale-string .00003 #t) $12 = "3.0e RUB " And my guile version: scheme@(guile-user)> (version) $13 = "2.0.11" It seems `number->locale-string' is broken. If I do, e.g. (number->locale-string .00003 10) it yields "3,0e-5" If the last arg decreases, it just trims the number of characters after comma, which is wrong in this case. Output for zero is funny, too. Regards, Vladimir