/** * @test * @dataProvider float_copy */ public function check_float_copy(FN $i, $scale) { $copy = $i->copy($scale); $this->assertSame($i->getValue(), $copy->getValue()); $this->assertSame($i->getOrigin(), $copy->getOrigin()); $this->assertEquals($scale, $copy->getScale()); }
/** * @param string|int|float|\Enimiste\Math\VO\FloatNumber $value * * @param int $scale * * @return \Enimiste\Math\VO\FloatNumber */ function as_float_number($value, $scale = 2) { if ($value instanceof \Enimiste\Math\VO\FloatNumber) { return $value->copy($scale); } else { if ($scale < 0) { throw new \RuntimeException('Scale should be >= 0'); } if ($value instanceof \Enimiste\Math\VO\IntegerNumber) { $value = $value->__toString(); } return new \Enimiste\Math\VO\FloatNumber($value, $scale); } }