1

Can someone explain me, how strtod works resp. why I get here 10,2 despite the en_EN-locale?

#!/usr/bin/env perl
use warnings;
use 5.012;
use POSIX qw(locale_h strtod);

setlocale( LC_NUMERIC, 'en_EN.UTF-8' );

my $str = '5,6';

$! = 0;
my ( $num, $n_unparsed ) = strtod( $str );

if ( $str eq '' or $n_unparsed != 0 or $! ) {
    die "Non-numeric input $str" . $! ? ": $!\n" : "\n";
}

say $num + 4.6;

# 10,2
sid_com
  • 24,137
  • 26
  • 96
  • 187

1 Answers1

3

Your ISO 3166 identifier is wrong. Try US.

daxim
  • 39,270
  • 4
  • 65
  • 132