php-bignumbers icon indicating copy to clipboard operation
php-bignumbers copied to clipboard

Leading decimal not supported in fromString

Open mareeo opened this issue 2 years ago • 0 comments

When creating from a string value leading decimals cause a NaNInputError.

// Works
\Litipk\BigNumbers\Decimal::fromString('0.110');

// PHP Fatal error:  Uncaught Litipk\BigNumbers\Errors\NaNInputError: strValue must be a number
\Litipk\BigNumbers\Decimal::fromString('.110');

A simple fix would be adding the following to fromString()

if (substr($strValue, 0, 1) === '.') {
    $strValue = '0' . $strValue;
}

mareeo avatar Mar 14 '22 22:03 mareeo