Velocity Reviews > Perl > How to change decimal point ',' to decimal comma ','

# How to change decimal point ',' to decimal comma ','

PERO
Guest
Posts: n/a

 04-13-2007
How to change decimal point ',' to decimal comma ','

eg:

\$num=1345,25;
TNX

Reinhard Pagitsch
Guest
Posts: n/a

 04-13-2007
PERO wrote:
> How to change decimal point ',' to decimal comma ','
>
> eg:
>
> \$num=1345,25;
> TNX
>
>

my \$num=120.269;
print \$num, "\n";
\$num =~ s/\./,/;
print \$num, "\n";
regards,
Reinhard

--
PM Mails an rpirpag <at> gmx dot at

Josef Moellers
Guest
Posts: n/a

 04-13-2007
PERO wrote:
> How to change decimal point ',' to decimal comma ','

Huh?

> eg:
>
> \$num=1345,25;

You could try using a text editor.
Ages ago, a suitable suggestion would be to post it on Usenet ...

What exactly are you trying to accomplish, what code have you written so

--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

Mirco Wahab
Guest
Posts: n/a

 04-13-2007
PERO wrote:
> How to change decimal point ',' to decimal comma ','
>
> eg:
>
> \$num=1345,25;
> TNX

Wild guess:

...

use POSIX;

my \$num = "1345,25"; # ==> '1345,25' as "numeric literal"

setlocale(LC_ALL, "de_DE"); # "de" has comma as decimal point
my \$m = strtod( \$num ); # \$m ==> '1345.25' now converted!
printf "%.3f\n", \$m+\$m;

setlocale(LC_ALL, "C");
printf "%.3f\n", \$m+\$m;

...

prints here (5.8.8 on Linux):

2690,500
2690.500

which is what one would expect.

Regards

Mirco

Brian McCauley
Guest
Posts: n/a

 04-13-2007
On Apr 13, 1:09 pm, "PERO" <(E-Mail Removed)> wrote:
> How to change decimal point ',' to decimal comma ','
>
> eg:
>
> \$num=1345,25;
> TNX

There is AFAIK no way to get Perl to recognise a decimal comma in
numeric literals in Perl source code.

If you are talking about _data_ not _code_ then the locale-based
solutions or simple string manipulations will do the trick. For string
manipulations I'd use tr/./,/ rather than s/\./,/.