guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Formatted output with locale


From: Vladimir Zhbanov
Subject: Re: Formatted output with locale
Date: Wed, 23 Nov 2016 15:06:56 +0300

Hi Ludovic,

...

>> 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 address@hidden so we keep track of it?

I don't know how to do this, sorry. I see bugs are numbered
there. Is there a special form for bug submission? Or just will an
email do? And how to answer the mail already being there if I'm
not subscribed?

>
>>> 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---


My Scheme output is as follows:
--------------------------------8<--------------------------------
scheme@(guile-user)> ,use (ice-9 i18n)
scheme@(guile-user)> (define l (make-locale LC_ALL "ru_RU.UTF-8"))
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 = "\xa0"
-------------------------------->8--------------------------------

(The last result is weird on my system though it's another story.)

I don't think all this somehow affects my output. I seem to have
found several bugs in number->locale-string().


1) Superfluous minus sign in output of zero:

--------------------------------8<--------------------------------
scheme@(guile-user)> (number->locale-string 0)
$5 = "0"
scheme@(guile-user)> (number->locale-string 0.0)
$6 = "-0,0"
-------------------------------->8--------------------------------

For this case a patch against the master branch is attached.


2) Wrong output for numbers less than 0.001

--------------------------------8<--------------------------------
scheme@(guile-user)> (number->locale-string 0.0009)
$7 = "9,0e-4"
scheme@(guile-user)> (number->locale-string 0.0009 2)
$8 = "9,0e"
scheme@(guile-user)> (number->locale-string 0.0009 1)
$9 = "9,0"
scheme@(guile-user)> (number->locale-string 0.0009 0)
$10 = "9"
-------------------------------->8--------------------------------

I don't really know how to proceed here. My naive approach is to
not modify the decimal part in such cases. The solution is in the
second patch.

3) Should output for the below cases differ?
--------------------------------8<--------------------------------
scheme@(guile-user)> (number->locale-string 10 2)
$2 = "10"
scheme@(guile-user)> (number->locale-string 10.0 2)
$3 = "10,0"
-------------------------------->8--------------------------------

4) Definitely a bug with different fraction-digits:
--------------------------------8<--------------------------------
scheme@(guile-user)> (number->locale-string 10.0 2)
$3 = "10,0"
scheme@(guile-user)> (number->locale-string 10.0 4)
$4 = "10,0"
-------------------------------->8--------------------------------

I think, the decimal parts should be zero padded to get desired
result.

5) Eventually, I don't really understand why substring() is used
to cut decimals:

--------------------------------8<--------------------------------
scheme@(guile-user)> (number->locale-string 0.99 0)
$8 = "0"
scheme@(guile-user)> (number->locale-string 0.99 1)
$9 = "0,9"
scheme@(guile-user)> (number->locale-string 0.99 2)
$10 = "0,99"
-------------------------------->8--------------------------------

I would prefer some rounding here in order to have the result as
follows:

--Desired results---------------8<-------------------------Begin--
scheme@(guile-user)> (number->locale-string 0.99 0)
$8 = "1"
scheme@(guile-user)> (number->locale-string 0.99 1)
$9 = "1,0"
scheme@(guile-user)> (number->locale-string 0.99 2)
$10 = "0,99"
--Desired results--------------->8---------------------------End--

Regards,
  Vladimir

Attachment: 0001-Fix-output-of-0.0-in-number-locale-string.patch
Description: Binary data

Attachment: 0002-Fix-number-locale-string-for-numbers-less-than-.001.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]