convert.

@param \Akaunting\Money\Currency $currency
@param int|float                 $ratio
@param int                       $roundingMode

@throws \InvalidArgumentException
@throws \OutOfBoundsException

@return \Akaunting\Money\Money
437838
public function convert(Currency $currency, $ratio, $roundingMode = self::ROUND_HALF_UP)
    {
        $this->currency = $currency;

        $this->assertOperand($ratio);
        $this->assertRoundingMode($roundingMode);

        if ($ratio < 1) {
            return $this->divide($ratio, $roundingMode);
        }

        return $this->multiply($ratio, $roundingMode);
    }
257752
public function divide(
        Fiat\Money $money,
        $fraction
    ): Fiat\Money {
        return $this->accountant->divide($money, $fraction);
    }
750141
@Override
    public Money divide(Number divisor) {
        if (NumberVerifier.isInfinityAndNotNaN(divisor)) {
            return Money.of(0, getCurrency());
        }
        BigDecimal divisorBD = MoneyUtils.getBigDecimal(divisor);
        if (divisorBD.equals(BigDecimal.ONE)) {
            return this;
        }
        BigDecimal dec =
                this.number.divide(divisorBD, MoneyUtils.getMathContext(getContext(), RoundingMode.HALF_EVEN));
        return new Money(dec, getCurrency());
    }
495682
public function amount($money)
    {
        if (null === $money) {
            return;
        }

        if (is_string($money) || $money < 0) {
            throw new InvalidArgumentException('Money amount must be a positive number.');
        }

        if ($this->getMoneyFormat() === 'cents') {
            return number_format($money, 0, '', '');
        }

        return sprintf('%.2f', number_format($money, 2, '.', '') / 100);
    }
1105165
public function divide($divisor, $roundingMode = self::ROUND_HALF_UP)
    {
        $this->assertOperand($divisor);
        $this->assertRoundingMode($roundingMode);

        if ($divisor == 0) {
            throw new InvalidArgumentException('Division by zero');
        }

        return new self(round($this->amount / $divisor, $this->currency->getPrecision(), $roundingMode), $this->currency);
    }
1201016
public function fromFloat($amount, $currency = null)
    {
        if ($currency) {
            $this->setCurrency($currency);
        }

        if (!is_float($amount)) {
            throw new InvalidArgumentException(sprintf(
                'Amount must be a float, %s given',
                gettype($amount)
            ));
        }
        
        $this->amount = $this->toInt(
            round(
                $this->getSubUnit() * round($amount, $this->getFractionDigits(), PHP_ROUND_HALF_UP),
                0,
                PHP_ROUND_HALF_UP
            )
        );
        return $this;
    }
456552
function convert( $fromCurrency, $toCurrency, $value, $applyRounding = true )
    {
        if ( $fromCurrency == false || $toCurrency == false || $fromCurrency == $toCurrency || $value == 0 )
            return $value;

        $math = $this->mathHandler();

        $crossRate = $this->crossRate( $fromCurrency, $toCurrency );
        $convertedValue = $math->mul( $value, $crossRate );
        if ( $applyRounding )
        {
            switch ( $this->roundingType() )
            {
                case 'EZ_CURRENCY_CONVERTER_ROUNDING_TYPE_ROUND':
                {
                    $convertedValue = $math->round( $convertedValue, $this->roundingPrecision(), $this->roundingTarget() );
                } break;

                case 'EZ_CURRENCY_CONVERTER_ROUNDING_TYPE_CEIL':
                {
                    $convertedValue = $math->ceil( $convertedValue, $this->roundingPrecision(), $this->roundingTarget() );
                } break;

                case 'EZ_CURRENCY_CONVERTER_ROUNDING_TYPE_FLOOR':
                {
                    $convertedValue = $math->floor( $convertedValue, $this->roundingPrecision(), $this->roundingTarget() );
                } break;

                case 'EZ_CURRENCY_CONVERTER_ROUNDING_TYPE_NONE':
                default:
                    break;
            }
        }

        return $convertedValue;
    }
219437
@Override
    public RoundedMoney subtract(MonetaryAmount subtrahend) {
        MoneyUtils.checkAmountParameter(subtrahend, currency);
        if (subtrahend.isZero()) {
            return this;
        }
        MathContext mc = monetaryContext.get(MathContext.class);
        if(mc==null){
            mc = MathContext.DECIMAL64;
        }
        return new RoundedMoney(number.subtract(subtrahend.getNumber().numberValue(BigDecimal.class), mc),
                currency, rounding);
    }
1288280
@Override
    public RoundedMoney remainder(Number divisor) {
        return new RoundedMoney(number.remainder(MoneyUtils.getBigDecimal(divisor), Optional.ofNullable(
                monetaryContext.get(MathContext.class)).orElse(MathContext.DECIMAL64)),
                currency, rounding);
    }
855543
public function amount($money)
    {
        if (null === $money) {
            return null;
        }

        $cents = $money * 100;
        if (!is_numeric($money) || $money < 0) {
            throw new \InvalidArgumentException('money amount must be a positive number.');
        }

        return ($this->money_format() == 'cents')
            ? number_format($cents, 0, '', '')
            : number_format($money, 2);
    }
618220
@Override
    public RoundedMoney subtract(MonetaryAmount amount) {
        MoneyUtils.checkAmountParameter(amount, currency);
        if (amount.isZero()) {
            return this;
        }
        return new RoundedMoney(number.subtract(amount.getNumber().numberValue(BigDecimal.class),
                Optional.ofNullable(
                        monetaryContext.get(MathContext.class)).orElse(MathContext.DECIMAL64)),
                currency, rounding);
    }
893711
public RoundedMoney with(Number amount) {
        checkNumber(amount);
        return new RoundedMoney(MoneyUtils.getBigDecimal(amount), currency, rounding);
    }
172205
public function multiply(float $factor, int $roundingMode) : Money
    {
        if (!in_array($roundingMode, self::$roundingModes, true)) {
            throw InvalidArgumentException::format(
                'Invalid rounding mode supplied to %s: expecting one of (%s), %s given',
                __METHOD__, Debug::formatValues(self::$roundingModes), $roundingMode
            );
        }

        return new Money((int)round($this->amount * $factor, 0, $roundingMode), $this->currency);
    }
1171784
private function createMoney($amount, $currency) { $precision = isset($this->config[$currency]) ? $this->config[$currency]['precision'] : 2;
        return new Money($amount, new Currency($currency, $precision));
    }
661474
public function create($amount, $currency)
    {
        $result = new Money($amount, $currency);
        $this->validator->validateMoney($result);
        return $result;
    }
940103
public function getBalance($currency = '')
    {
        $currency = strtoupper($currency);
        $url = 'balance';
        if (!empty($currency)) {
            $url .= '/' . strtoupper($currency);
        }

        $requestResult = $this->sendRequest($url);

        return $this->handleResult($requestResult);
    }
1230425
public function multiply(
        Money $money,
        $fraction
    ): Money {
        return new Money(
            $money->getAmount() * $fraction,
            $money->getCurrency()
        );
    }