Skip to content

Commit 8a9665e

Browse files
committed
Cast int to float
1 parent d81d93e commit 8a9665e

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

lib/Parameter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public function bool(): bool
4141

4242
public function float(): float
4343
{
44+
if (is_int($this->value)) {
45+
return (float)$this->value;
46+
}
4447
if (!is_float($this->value)) {
4548
throw new RuntimeException(sprintf('Value is not a float, it is "%s"', gettype($this->value)));
4649
}

tests/Unit/ParameterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function testCast(): void
1717
self::assertSame('12', (new Parameter('12'))->string());
1818
self::assertSame(true, (new Parameter(true))->bool());
1919
self::assertSame(12.2, (new Parameter(12.2))->float());
20+
self::assertSame(12.0, (new Parameter(12))->float());
2021
}
2122

2223
/**

0 commit comments

Comments
 (0)