Locales on Win32, with numbers

D

damjensen

I have some questions about Locales on Win32 (Perl 5.10.0, Activeperl)

I needed to process Excel sheets with numbers, formattet with comma as
decimal point.

In my programming I found this peculiar difference:

Danish POSIX local, which fails (drops decimal value):
use strict;
use locale;
use POSIX;

POSIX::setlocale( &POSIX::LC_ALL, "da" );
my $number1 = "-123,44";
my $number2 = 10;
my $result = $number1 / $number2;

printf ('%4.4f', $result);
printf ('%4.4f', $number1 * -1);


GERMAN version which works (discovered by mistake):
use strict;
use locale;
use POSIX;

POSIX::setlocale( &POSIX::LC_ALL, "ge" );
my $number1 = "-123,44";
my $number2 = 10;
my $result = $number1 / $number2;

printf ('%4.4f', $result);
printf ('%4.4f', $number1 * -1);


This leads me to my questions:

1) where is the use of Locale and Win32 documented ? The perllocale
mentions NOTHING of Win32, and their examples using setlocale(.. )
fails.

2) why are languages on Win32 different, and where is this
documented ? Maybe an MS thing...

3) can I import a module to make locales work as Unix, on Win32
systems.

4) can I change Danish setting to make it work with decimal numbers.

Hope some expert in Locales can help me.
 
A

A. Sinan Unur

(e-mail address removed) wrote in @k36g2000yqe.googlegroups.com:
Danish POSIX local, which fails (drops decimal value):
use strict;
use locale;
use POSIX;

POSIX::setlocale( &POSIX::LC_ALL, "da" );
my $number1 = "-123,44";
my $number2 = 10;
my $result = $number1 / $number2;

printf ('%4.4f', $result);
printf ('%4.4f', $number1 * -1);

I would not call the following a 'fail':

C:\DOCUME~1\asu1\LOCALS~1\Temp> cat t.pl
use strict;
use locale;
use POSIX;

POSIX::setlocale( &POSIX::LC_ALL, "da" );
my $number1 = "-123,44";
my $number2 = 10;
my $result = $number1 / $number2;

printf ("%4.4f\n", $result);
printf ("%4.4f\n", $number1 * -1);

C:\DOCUME~1\asu1\LOCALS~1\Temp> t
-12,3440
123,4400

C:\DOCUME~1\asu1\LOCALS~1\Temp> perl -v

This is perl, v5.10.0 built for MSWin32-x86-multi-thread
(with 5 registered patches, see perl -V for more detail)

Copyright 1987-2007, Larry Wall

Binary build 1004 [287188] provided by ActiveState
http://www.ActiveState.com
Built Sep 3 2008 13:16:37

Tested on a U.S. English Windows XP SP3 system. Hope this helps.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
D

damjensen

Thanks for your test.

Not sure what the reason is, only thing I can see is that you use a US
system, I use a Danish Windows setup and a Danish
locale in Windows.

No matter what I do, the Danish setting still does not work for me.


Can anyone point at resources for Perl and Windows locale
documentation ? (to match perllocale which targets Unix)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top