2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-20 07:16:03 +00:00

UConv: use SI standard for thousands_sep

git-svn-id: https://svn.fhem.de/fhem/trunk@19618 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2019-06-14 12:02:14 +00:00
parent 7aaedd9d21
commit b221fa1591

View File

@ -9,6 +9,7 @@ package UConv;
use strict; use strict;
use warnings; use warnings;
use POSIX; use POSIX;
use utf8;
use Math::Trig; use Math::Trig;
use Scalar::Util qw(looks_like_number); use Scalar::Util qw(looks_like_number);
@ -2089,33 +2090,32 @@ sub _GetSeasonPheno ($$;$$) {
# HELPER FUNCTIONS # HELPER FUNCTIONS
sub decimal_mark ($;$) { sub decimal_mark ($;$) {
return $_[0] unless ( looks_like_number($_[0]) ); return $_[0] unless ( looks_like_number( $_[0] ) );
my $d = reverse $_[0]; my $d = reverse $_[0];
my $locale = ( $_[1] ? $_[1] : undef ); my $locale = ( $_[1] ? $_[1] : undef );
my $old_locale = setlocale(LC_NUMERIC); my $old_locale = setlocale(LC_NUMERIC);
setlocale(LC_NUMERIC, $locale) if ($locale); setlocale( LC_NUMERIC, $locale ) if ($locale);
use locale ':not_characters'; use locale ':not_characters';
my ( $decimal_point, $thousands_sep, $grouping ) = my ( $decimal_point, $thousands_sep, $grouping ) =
@{ localeconv() }{ 'decimal_point', 'thousands_sep', 'grouping' }; @{ localeconv() }{ 'decimal_point', 'thousands_sep', 'grouping' };
setlocale(LC_NUMERIC, ""); setlocale( LC_NUMERIC, "" );
setlocale(LC_NUMERIC, $old_locale); setlocale( LC_NUMERIC, $old_locale );
no locale; no locale;
$thousands_sep = ($decimal_point && $decimal_point eq ',' ? '.' : ',') $thousands_sep = chr(0x2009) unless ($thousands_sep);
unless ($thousands_sep); my @grouping =
my @grouping = $grouping && $grouping =~ /^\d+$/ ? unpack( "C*", $grouping ) : (3);
$grouping && $grouping =~ /^\d+$/ ? unpack( "C*", $grouping ) : (3);
if ( $thousands_sep eq '.' ) { if ( $thousands_sep ne ',' ) {
$d =~ s/\./$decimal_point/g; $d =~ s/\./$decimal_point/g;
$d =~ s/(\d{$grouping[0]})(?=\d)(?!\d*,)/$1$thousands_sep/g; $d =~ s/(\d{$grouping[0]})(?=\d)(?!\d*,)/$1$thousands_sep/g;
} }
else { else {
$d =~ s/(\d{$grouping[0]})(?=\d)(?!\d*\.)/$1$thousands_sep/g; $d =~ s/(\d{$grouping[0]})(?=\d)(?!\d*\.)/$1$thousands_sep/g;
} }
return scalar reverse $d; return scalar reverse $d;
} }
sub _round($;$) { sub _round($;$) {