unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Martin Michel <dev@famic.de>
Cc: Vladimir Zhbanov <vzhbanov@gmail.com>, 24990-done@debbugs.gnu.org
Subject: bug#24990: Wrong formatted output with 'number->locale-string'
Date: Mon, 13 Feb 2017 00:24:00 +0100	[thread overview]
Message-ID: <87k28vq9gv.fsf@gnu.org> (raw)
In-Reply-To: <20161122214801.GA20536@remote.famic.de> (Martin Michel's message of "Tue, 22 Nov 2016 22:48:01 +0100")

Hi,

Martin Michel <dev@famic.de> skribis:

> From: Vladimir Zhbanov <vzhbanov@gmail.com>
> Subject: Re: Formatted output with locale
> To: dev@famic.de, 24990@debbugs.gnu.org
> Date: Mon, 14 Nov 2016 09:03:19 +0300 (12 weeks, 6 days, 15 hours ago)
>
> Hi Martin,
>
> On 11/13/16, dev@famic.de <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 "

I believe these are fixed by commit
4aead68cdb86ca60cc372f0cd558cadda90ddec5.

You’re welcome to do more testing and report back!

Thanks,
Ludo’.





      reply	other threads:[~2017-02-12 23:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-22 21:48 bug#24990: Wrong formatted output with 'number->locale-string' Martin Michel
2017-02-12 23:24 ` Ludovic Courtès [this message]

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=87k28vq9gv.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=24990-done@debbugs.gnu.org \
    --cc=dev@famic.de \
    --cc=vzhbanov@gmail.com \
    /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).