Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit ac8b378

Browse files
committed
add support for leading zeros in exponent
1 parent 59e8417 commit ac8b378

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Decimal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public static function fromString($strValue, $scale = null)
177177
max(0, strlen($captures[4])-1) :
178178
0;
179179

180-
} elseif (preg_match('/([+\-]?)0*([0-9](\.[0-9]+)?)[eE]([+\-]?)([1-9][0-9]*)/', $strValue, $captures) === 1) {
180+
} elseif (preg_match('/([+\-]?)0*([0-9](\.[0-9]+)?)[eE]([+\-]?)(\d+)/', $strValue, $captures) === 1) {
181181

182182
$mantissa_scale = max(strlen($captures[3])-1, 0);
183183

tests/Decimal/DecimalFromStringTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ public function testExponentialNotation_With_PositiveSign()
8989
);
9090
}
9191

92+
public function testExponentialNotation_With_LeadingZero_in_ExponentPart()
93+
{
94+
$this->assertTrue(
95+
Decimal::fromString('1.048576E+06')->equals(Decimal::fromString('1.048576e6'))
96+
);
97+
}
98+
99+
public function testExponentialNotation_With_ZeroExponent()
100+
{
101+
$this->assertTrue(
102+
Decimal::fromString('3.14E+00')->equals(Decimal::fromString('3.14'))
103+
);
104+
}
105+
92106
/**
93107
* @expectedException Litipk\Exceptions\InvalidArgumentTypeException
94108
* @expectedExceptionMessage $strVlue must be of type string.

0 commit comments

Comments
 (0)