Coder-Spirit / php-bignumbers

A robust library to handle immutable big numbers inside PHP applications
MIT License
131 stars 29 forks source link

Leading decimal not supported in fromString #76

Open mareeo opened 2 years ago

mareeo commented 2 years ago

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;
}