Skip to content

Commit

Permalink
Fix German negative numbers (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwn authored Feb 24, 2024
1 parent bf8e9d9 commit 0b29195
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ workflows:
name: build-php-<< matrix.php_version >>
matrix:
parameters:
php_version: ["8.0", "8.1", "8.2"]
php_version: ["8.0", "8.1", "8.2", "8.3"]
xdebug_version: ["stable"]
2 changes: 1 addition & 1 deletion src/Language/German/GermanDictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class GermanDictionary implements Dictionary

public function getMinus(): string
{
return 'Minus';
return 'minus';
}

public function getZero(): string
Expand Down
5 changes: 3 additions & 2 deletions src/NumberTransformer/GenericNumberTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ public function toWords(int $number): string
}

$words = [];
$minus = '';

if ($number < 0) {
$words[] = $this->dictionary->getMinus();
$minus = $this->dictionary->getMinus();
$number *= -1;
}

if (null !== $this->tripletTransformer || null !== $this->powerAwareTripletTransformer) {
$words = array_merge($words, $this->getWordsBySplittingIntoTriplets($number));
}

return trim(implode($this->wordsSeparator, $words));
return trim(sprintf('%s %s', $minus, implode($this->wordsSeparator, $words)));
}

private function getWordsBySplittingIntoTriplets(int $number): array
Expand Down
2 changes: 2 additions & 0 deletions tests/NumberTransformer/GermanNumberTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ protected function setUp(): void
public function providerItConvertsNumbersToWords(): array
{
return [
[-287, 'minus zweihundertsiebenundachtzig'],
[-10, 'minus zehn'],
[0, 'null'],
[1, 'eins'],
[2, 'zwei'],
Expand Down

0 comments on commit 0b29195

Please sign in to comment.