Prev: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.9 $)
Next: Where is the document for \ (backslash operator for creating a reference)
From: Pete Sammet on 4 Jun 2010 06:15 As I found out by default Perl produces floating point number output as 123456.78 where ".78" is the fraction part of the number. However in Europe another format is used: 123456,78 How exactly can I switch from the first to the second format? I read a solution with $myvar ~= tr/./,/; but I don't want such a "afterwork" transformation. The output should AUTOMATICALLY contain "," even during the calculation: $num = 5/4; print $num; should show 1,25 Pete
From: Denis McMahon on 4 Jun 2010 08:43 On 04/06/10 11:15, Pete Sammet wrote: > where ".78" is the fraction part of the number. > However in Europe another format is used: > 123456,78 First hit of google for "perl locale" looked relevant. Rgds Denis McMahon
From: Tad McClellan on 4 Jun 2010 09:10 Pete Sammet <petesammet(a)mail.org> wrote: > However in Europe another format is used: > > 123456,78 "Europe" is many many locales. I will assume czechoslovakia as it is one of those that use comma as the decimal point. > How exactly can I switch from the first to the second format? perldoc perllocale ---------------------------- #!/usr/bin/perl use warnings; use strict; use locale; use POSIX qw(locale_h LC_NUMERIC); setlocale(LC_NUMERIC, "cs_CZ"); print 5/4, "\n"; ---------------------------- -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" The above message is a Usenet post. I don't recall having given anyone permission to use it on a Web site.
From: Ben Morrow on 5 Jun 2010 16:33 Quoth Tad McClellan <tadmc(a)seesig.invalid>: > Pete Sammet <petesammet(a)mail.org> wrote: > > > However in Europe another format is used: > > > > 123456,78 > > "Europe" is many many locales. I will assume czechoslovakia as it > is one of those that use comma as the decimal point. > > > How exactly can I switch from the first to the second format? > > perldoc perllocale > > ---------------------------- > #!/usr/bin/perl > use warnings; > use strict; > > use locale; > use POSIX qw(locale_h LC_NUMERIC); > setlocale(LC_NUMERIC, "cs_CZ"); This is a bad plan. Locales (specifically, the 'locale' pragma) and Unicode don't play nicely together in Perl, and if you're processing international text you will probably end up with Unicode strings. A better answer would be to use a CPAN module for number formatting, such as Number::Format. Ben
From: Martijn Lievaart on 7 Jun 2010 07:04
On Sat, 05 Jun 2010 21:33:20 +0100, Ben Morrow wrote: > This is a bad plan. Locales (specifically, the 'locale' pragma) and > Unicode don't play nicely together in Perl, and if you're processing > international text you will probably end up with Unicode strings. A Can you expand on this? What exactly goes wrong (or is unexpected)? M4 |