Skip to content

Commit

Permalink
Merge pull request #16 from gdsrmygdsrjr/main
Browse files Browse the repository at this point in the history
Fix if the decimal is only 0
  • Loading branch information
rmunate authored Oct 13, 2023
2 parents e07361c + 418991d commit 2333c74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Miscellaneous/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function isNotExceedMax($value)
if (self::isValidString($value) || self::isValidDouble($value)) {
$parts = explode('.', $value);
$integerPart = intval($parts[0]);
$decimalPart = intval($parts[1]);
$decimalPart = intval($parts[1] ?? 0);

$validateInteger = is_numeric($integerPart) && filter_var($integerPart, FILTER_VALIDATE_INT) !== false;
$validateDecimal = is_numeric($decimalPart) && filter_var($decimalPart, FILTER_VALIDATE_INT) !== false;
Expand Down
10 changes: 10 additions & 0 deletions src/SpellNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ private function integerToLetters()
private function doubleToLetters()
{
$parts = explode('.', $this->value);

if (!array_key_exists(1, $parts)) {
return $this->integerToLetters();
}

$letters1 = NumberFormatterWrapper::format($parts[0], $this->locale);
$letters2 = NumberFormatterWrapper::format($parts[1], $this->locale);

Expand Down Expand Up @@ -181,6 +186,11 @@ private function integerToMoney()
private function doubleToMoney()
{
$parts = explode('.', $this->value);

if (!array_key_exists(1, $parts)) {
return $this->integerToMoney();
}

$letters1 = NumberFormatterWrapper::format($parts[0], $this->locale);
$letters1 = Replaces::locale($letters1, $this->locale, $this->currency);

Expand Down

0 comments on commit 2333c74

Please sign in to comment.