From: Rafael Garcia-Suarez Date: Sun, 8 Oct 2006 17:07:42 +0000 (+0000) Subject: Clarifications on the usage of setlocale() and LC_NUMERIC to X-Git-Tag: accepted/trunk/20130322.191538~16910 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7e4353e96785be675a69a6886d154405dbfdc124;p=platform%2Fupstream%2Fperl.git Clarifications on the usage of setlocale() and LC_NUMERIC to affect the decimal point in output, by Jarkko. p4raw-id: //depot/perl@28965 --- diff --git a/pod/perldata.pod b/pod/perldata.pod index 82ad855..cbfe070 100644 --- a/pod/perldata.pod +++ b/pod/perldata.pod @@ -337,6 +337,12 @@ X There is no double interpolation in Perl, so the C<$100> is left as is. +By default floating point numbers substituted inside strings use the +dot (".") as the decimal separator. If C is in effect, +and POSIX::setlocale() has been called, the character used for the +decimal separator is affected by the LC_NUMERIC locale. +See L and L. + As in some shells, you can enclose the variable name in braces to disambiguate it from following alphanumerics (and underscores). You must also do diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index bcedd53..af5fe70 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -4127,9 +4127,10 @@ X Equivalent to C, except that C<$\> (the output record separator) is not appended. The first argument of the list will be interpreted as the C format. See C -for an explanation of the format argument. If C is in effect, -the character used for the decimal point in formatted real numbers is -affected by the LC_NUMERIC locale. See L. +for an explanation of the format argument. If C is in effect, +and POSIX::setlocale() has been called, the character used for the decimal +separator in formatted floating point numbers is affected by the LC_NUMERIC +locale. See L and L. Don't fall into the trap of using a C when a simple C would do. The C is more efficient and less @@ -5740,9 +5741,10 @@ index, the C<$> may need to be escaped: =back -If C is in effect, the character used for the decimal -point in formatted real numbers is affected by the LC_NUMERIC locale. -See L. +If C is in effect, and POSIX::setlocale() has been called, +the character used for the decimal separator in formatted floating +point numbers is affected by the LC_NUMERIC locale. See L +and L. =item sqrt EXPR X X X diff --git a/pod/perllocale.pod b/pod/perllocale.pod index 8f7ce04..3624903 100644 --- a/pod/perllocale.pod +++ b/pod/perllocale.pod @@ -909,6 +909,23 @@ category-specific C. =back +=head2 Examples + +The LC_NUMERIC controls the numeric output: + + use locale; + use POSIX qw(locale_h); # Imports setlocale() and the LC_ constants. + setlocale(LC_NUMERIC, "fr_FR") or die "Pardon"; + printf "%g\n", 1.23; # If the "fr_FR" succeeded, probably shows 1,23. + +and also how strings are parsed by POSIX::strtod() as numbers: + + use locale; + use POSIX qw(locale_h strtod); + setlocale(LC_NUMERIC, "de_DE") or die "Entshuldigung"; + my $x = strtod("2,34") + 5; + print $x, "\n"; # Probably shows 7,34. + =head1 NOTES =head2 Backward compatibility