Subject: | multi-char thousands separator |
Number::Format doesn't support a multiple character thousands separator;
however, it's simple to implement. Would you mind accepting the
attached patch to add support for it? It includes a new test and a POD
update.
If I'm missing another reason why this shouldn't be supported, please
let me know. Thanks for your consideration.
Best,
Nick Patch
Subject: | number-format.patch |
diff --git Format.pm Format.pm
index 4f736e0..63d4013 100644
--- Format.pm
+++ Format.pm
@@ -142,8 +142,8 @@ higher are not implemented because of integer overflows on 32-bit
systems.
The only restrictions on C<DECIMAL_POINT> and C<THOUSANDS_SEP> are that
-they must not be digits, must not be identical, and must each be one
-character. There are no restrictions on C<INT_CURR_SYMBOL>.
+they must not be digits and must not be identical. There are no
+restrictions on C<INT_CURR_SYMBOL>.
For example, a German user might include this in their code:
@@ -577,8 +577,8 @@ sub format_number
$integer = join($thousands_sep,
grep {$_ ne ''} split(/(...)/, $integer));
- # Strip off leading zeroes and/or comma
- $integer =~ s/^0+\Q$thousands_sep\E?//;
+ # Strip off leading zeroes and optional thousands separator
+ $integer =~ s/^0+(?:\Q$thousands_sep\E)?//;
}
$integer = '0' if $integer eq '';
diff --git t/object.t t/object.t
index ca485a3..c6d2110 100644
--- t/object.t
+++ t/object.t
@@ -17,3 +17,14 @@ isa_ok($deutsch, 'Number::Format', 'object');
is($deutsch->format_number(1234567.509, 2), '1.234.567,51', 'round');
is($deutsch->format_number(12345678.5, 2), '12.345.678,5', 'tousends');
is($deutsch->format_number(1.23456789, 6), '1,234568', 'big frac');
+
+my $double_char = Number::Format->new(
+ -thousands_sep => ' ',
+ -decimal_point => ',',
+);
+
+is(
+ $double_char->format_number(12345678.5),
+ "12 345 678,5",
+ 'multi-char thousands separator'
+);