public function testFloatPrecision() { $locale = 'en_US'; $currencyCode = 'EUR'; $currency = new Currency($locale, $currencyCode); $uncurrency = new Uncurrency($locale, $currencyCode); $from = -100; $to = $from + 1100; $precision = 2; $divisor = pow(10, $precision); for ($i = $from; $i <= $to; $i++) { $testValue = (double) $i / $divisor; $stringValue = $currency->filter($testValue); $value = $uncurrency->filter($stringValue); // echo $testValue . ' -> ' . $stringValue . ' -> ' . $value . PHP_EOL; // DEBUG $this->assertInternalType('string', $stringValue); $this->assertInternalType('double', $value); $this->assertSame($testValue, $value); } $from = 100000000000000.0; $to = $from + 1000; $precision = 2; $divisor = pow(10, $precision); for ($i = $from; $i <= $to; $i++) { $testValue = (double) $i / $divisor; $stringValue = $currency->filter($testValue); $value = $uncurrency->filter($stringValue); // echo $testValue . ' -> ' . $stringValue . ' -> ' . $value . PHP_EOL; // DEBUG $this->assertInternalType('string', $stringValue); $this->assertInternalType('double', $value); $this->assertSame($testValue, $value); } }
public function testFloatWithImproperScale() { $filter = new Currency('it_IT'); $filter->setScaleCorrectness(true); $this->assertEquals(123456789.12345679, $filter->filter(123456789.12345679)); }