We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 1b93a71 + 02057a4 commit c35a24eCopy full SHA for c35a24e
src/Collection/Primitive/Number.php
@@ -76,4 +76,14 @@ public function asInteger(): int
76
{
77
return (int) $this->bigNumber->getValue();
78
}
79
+
80
+ /**
81
+ * Get the number as a float.
82
+ *
83
+ * @return float
84
+ */
85
+ public function asFloat(): float
86
+ {
87
+ return (float) $this->bigNumber->getValue();
88
+ }
89
tests/Unit/Primitive/NumberTest.php
@@ -17,6 +17,11 @@
17
$this->assertSame(100, $valueObject->asInteger());
18
});
19
20
+test('number can cast to float', function () {
21
+ $valueObject = new Number('36000.50');
22
+ $this->assertSame(36000.50, $valueObject->asFloat());
23
+});
24
25
test('number can accept string', function () {
26
$valueObject = new Number('1');
27
$this->assertSame('1.00', $valueObject->value());
0 commit comments