Skip to content

Commit 4dd9a87

Browse files
authored
Merge pull request #8932 from kenjis/fix-number-helper-type-error
fix: TypeError in number_to_amount()
2 parents 482b8bb + 3d6436e commit 4dd9a87

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

system/Helpers/number_helper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ function number_to_amount($num, int $precision = 0, ?string $locale = null)
8282
// Strip any formatting & ensure numeric input
8383
try {
8484
// @phpstan-ignore-next-line
85-
$num = 0 + str_replace(',', '', $num);
85+
$num = 0 + str_replace(',', '', (string) $num);
8686
} catch (ErrorException) {
87+
// Catch "Warning: A non-numeric value encountered"
8788
return false;
8889
}
8990

tests/system/Helpers/NumberHelperTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public function testRomanNumber(): void
3838
$this->assertSame('X', number_to_roman(10));
3939
}
4040

41+
public function testRomanNumberString(): void
42+
{
43+
$this->assertSame('XCVI', number_to_roman('96'));
44+
}
45+
4146
public function testRomanNumberRange(): void
4247
{
4348
$this->assertNull(number_to_roman(-1));
@@ -70,6 +75,11 @@ public function testNumberToSize(): void
7075
$this->assertSame('456 Bytes', number_to_size(456, 1, 'en_US'));
7176
}
7277

78+
public function testNumberToSizeString(): void
79+
{
80+
$this->assertSame('456 Bytes', number_to_size('456', 1, 'en_US'));
81+
}
82+
7383
public function testKbFormat(): void
7484
{
7585
$this->assertSame('4.5 KB', number_to_size(4567, 1, 'en_US'));
@@ -109,6 +119,11 @@ public function testThousands(): void
109119
$this->assertSame('1,000 thousand', number_to_amount('999999', 0, 'en_US'));
110120
}
111121

122+
public function testThousandsInt(): void
123+
{
124+
$this->assertSame('123 thousand', number_to_amount(123000, 0, 'en_US'));
125+
}
126+
112127
public function testMillions(): void
113128
{
114129
$this->assertSame('123.4 million', number_to_amount('123,400,000', 1, 'en_US'));

0 commit comments

Comments
 (0)