/** * {@inheritdoc} */ public function convertToPHPValue($value, AbstractPlatform $platform) { if ($value === null) { return null; } return BigDecimal::of($value); }
public static function main($argc, $argv) { if ($argc < 2) { echo 'Usage: php test.php number_of_files_to_copy' . PHP_EOL; exit; } $numFilesToCopy = (int) $argv[1]; if ($numFilesToCopy < 1) { $numFilesToCopy = 1; } $fileName = 'test.yml'; $filePath = __DIR__ . '/' . $fileName; $yamlArr = Yaml::parse(file_get_contents($filePath)); $newFilenamePrefix = $yamlArr['new_filename_prefix']; try { $filesystem = new Filesystem(); for ($i = 1; $i <= $numFilesToCopy; $i++) { $newFilepath = __DIR__ . "/{$newFilenamePrefix}_{$i}.yml"; $filesystem->copy($filePath, $newFilepath); } } catch (FileNotFoundException $e) { echo "File '{$filePath}' could not be found!" . PHP_EOL; } catch (IOException $e) { echo "Could not copy file '{$filePath}' to '{$newFilepath}'!" . PHP_EOL; } finally { // Just for fun unset($filesystem); } $funny = (int) ((0.7 + 0.1) * 10); echo $funny . PHP_EOL; $notFunny = BigDecimal::of(0.7)->plus(BigDecimal::of(0.1))->multipliedBy(10)->toInteger(); echo $notFunny . PHP_EOL; $notFunny = BigRational::of('7/10')->plus(BigRational::of('1/10'))->multipliedBy(10)->toInteger(); echo $notFunny . PHP_EOL; }
/** * Returns a copy of this Money converted into another currency. * * By default, the scale of the result is adjusted to represent the exact converted value. * For example, converting `USD 1.23` to `EUR` with an exchange rate of `0.91` will yield `USD 1.1193`. * The scale can be specified by providing a `MoneyContext` instance. * * @param Currency|string $currency The target currency or currency code. * @param BigNumber|number|string $exchangeRate The exchange rate to multiply by. * @param MoneyContext|null $context An optional context for scale & rounding. * * @return Money * * @throws UnknownCurrencyException If an unknown currency code is given. * @throws ArithmeticException If the exchange rate or rounding mode is invalid, or rounding is necessary. */ public function convertedTo($currency, $exchangeRate, MoneyContext $context = null) { $currency = Currency::of($currency); if ($context === null) { $context = new ExactContext(); } $amount = $this->amount->toBigRational()->multipliedBy($exchangeRate); $amount = $context->applyTo($amount, $currency, $this->amount->scale()); return new Money($amount, $currency); }
/** * {@inheritdoc} */ public function toBigDecimal() { return BigDecimal::create($this->value); }
/** * @expectedException \LogicException */ public function testDirectCallToUnserialize() { BigDecimal::zero()->unserialize('123:0'); }
/** * @param string $unscaledValue The expected unscaled value, as a string. * @param int $scale The expected scale. * @param BigDecimal $actual The BigDecimal instance to test. */ protected final function assertBigDecimalInternalValues($unscaledValue, $scale, $actual) { $this->assertInstanceOf(BigDecimal::getNamespace(), $actual); $this->assertSame($unscaledValue, $actual->unscaledValue()); $this->assertSame($scale, $actual->scale()); }
/** * {@inheritdoc} */ public function toScale($scale, $roundingMode = RoundingMode::UNNECESSARY) { $scale = (int) $scale; if ($scale === $this->scale) { return $this; } return $this->dividedBy(BigDecimal::one(), $scale, $roundingMode); }
/** * @param number|string|null $step The step, or null to remove it. * * @return static * * @throws \InvalidArgumentException If the step is not a valid number or not positive. */ public function setStep($step) { if ($step !== null) { $step = BigDecimal::of($step); if ($step->isNegativeOrZero()) { throw new \InvalidArgumentException('The number validator step must be strictly positive.'); } } $this->step = $step; return $this; }