Bug 2420 - de_CH: negative number formatting
Summary: de_CH: negative number formatting
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: localedata (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: GNU C Library Locale Maintainers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-06 04:58 UTC by Thomas Schwanhäuser
Modified: 2018-04-19 13:50 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
Fix strfmon to not omit the negative sign (416 bytes, patch)
2006-03-10 12:47 UTC, Denis Barbier
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Schwanhäuser 2006-03-06 04:58:21 UTC
Negative numbers don't get a leading "-" when formatted as a (financial) 
number like with other locales.

Expected result: -12.34
Actual result: 12.34
Comment 1 Denis Barbier 2006-03-07 21:12:23 UTC
I cannot reproduce your bug.  Can you please tell how you print
this negative amount?
Comment 2 Thomas Schwanhäuser 2006-03-08 11:51:33 UTC
(In reply to comment #1)
> I cannot reproduce your bug.  Can you please tell how you print
> this negative amount?

Here is a PHP script as a demo.

If I run it, I get this as an output:

Pos:  123 456.00
Neg: 123 456.00
 Switching to locale de_DE
Pos:  123.456,00
Neg: -123.456,00




Script:

<?PHP
$posnumber=123456; $negnumber=$posnumber*(-1);

setlocale (LC_ALL, 'de_CH');
print "Pos: ".money_format('',$posnumber)."\n";
print "Neg: ".money_format('',$negnumber);

print "\n Switching to locale de_DE \n";

setlocale(LC_ALL, 'de_DE');
print "Pos: ".money_format('',$posnumber)."\n";
print "Neg: ".money_format('',$negnumber);


?>


Comment 3 Thomas Schwanhäuser 2006-03-08 11:53:16 UTC
Please also note, that for de/fr/it_CH formatting it should be "123'456" 
instead of "123 456". See http://sourceware.org/bugzilla/show_bug.cgi?id=2349 
for more details.
Comment 4 Denis Barbier 2006-03-08 19:55:55 UTC
> print "Pos: ".money_format('',$posnumber)."\n";
> print "Neg: ".money_format('',$negnumber);

These commands print nothing here; according to PHP documentation,
the first argument of money_format cannot be empty, it must contain
%i or %n with optional attributes.
The minus sign is then printed as expected, so it seems that there
is no bug.
Comment 5 Denis Barbier 2006-03-10 06:54:42 UTC
After more explanations from Thomas, I can confirm that there is indeed a bug
with strfmon and the ! modifier. Here is a test case.
  Expected result: Fr.- 12.34 - 12.34
  Actual result: Fr.- 12.34 12.34

#include <monetary.h>
#include <locale.h>
#include <stdio.h>

int main()
{
	char buf[500];
	setlocale(LC_ALL, "de_CH.UTF-8");
	strfmon(buf, sizeof(buf), "%n %!n\n", -12.34, -12.34);
	printf("%s", buf);
	return 0;
}
Comment 6 Denis Barbier 2006-03-10 12:47:44 UTC
Created attachment 909 [details]
Fix strfmon to not omit the negative sign

Note: this patch does not modify indentation to improve its readability.
Comment 7 Ulrich Drepper 2006-04-26 05:15:54 UTC
Should be fixed in CVS.