Skip to content

Commit

Permalink
Revert removal of Money::fromFloat()
Browse files Browse the repository at this point in the history
Reverts eb32c53
Reverts 91c8091
  • Loading branch information
Ocramius committed Apr 23, 2021
1 parent 91c8091 commit 0ca2933
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/NumberSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ public function it_throws_an_exception_when_number_is_invalid(): void

$this->shouldThrow(InvalidArgumentException::class)->duringInstantiation();
}

public function it_creates_a_number_from_float(): void
{
$number = $this->fromFloat(1.1);

$number->shouldHaveType(Number::class);
$number->__toString()->shouldReturn('1.1');
}
}
6 changes: 6 additions & 0 deletions src/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public static function fromString(string $number): self
);
}

/** @psalm-pure */
public static function fromFloat(float $number): self
{
return self::fromString(sprintf('%.14F', $number));
}

/** @psalm-pure */
public static function fromNumber(int|string $number): self
{
Expand Down

0 comments on commit 0ca2933

Please sign in to comment.