Coder-Spirit/php-bignumbers

Leading decimal not supported in fromString

Opened this issue · 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;
}