Java Code Examples for javax.money.MonetaryAmount#divide()
The following examples show how to use
javax.money.MonetaryAmount#divide() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaMoneyUnitManualTest.java From tutorials with MIT License | 5 votes |
@Test(expected = ArithmeticException.class) public void givenAmount_whenDivided_thanThrowsException() { MonetaryAmount oneDolar = Monetary .getDefaultAmountFactory() .setCurrency("USD") .setNumber(1) .create(); oneDolar.divide(3); fail(); // if no exception }
Example 2
Source File: JavaMoneyUnitManualTest.java From tutorials with MIT License | 5 votes |
@Test public void givenArithmetic_whenStringified_thanEqualsAmount() { CurrencyUnit usd = Monetary.getCurrency("USD"); Money moneyof = Money.of(12, usd); MonetaryAmount fstAmtUSD = Monetary .getDefaultAmountFactory() .setCurrency(usd) .setNumber(200.50) .create(); MonetaryAmount oneDolar = Monetary .getDefaultAmountFactory() .setCurrency("USD") .setNumber(1) .create(); Money subtractedAmount = Money .of(1, "USD") .subtract(fstAmtUSD); MonetaryAmount multiplyAmount = oneDolar.multiply(0.25); MonetaryAmount divideAmount = oneDolar.divide(0.25); assertEquals("USD", usd.toString()); assertEquals("USD 1", oneDolar.toString()); assertEquals("USD 200.5", fstAmtUSD.toString()); assertEquals("USD 12", moneyof.toString()); assertEquals("USD -199.5", subtractedAmount.toString()); assertEquals("USD 0.25", multiplyAmount.toString()); assertEquals("USD 4", divideAmount.toString()); }
Example 3
Source File: PresentValueGrowingAnnuity.java From javamoney-lib with Apache License 2.0 | 3 votes |
/** * Performs the calculation. * * @param dividend the dividend payment * @param discountRate The discount rate, not null. * @param growthRate The growth rate, not null. * @return the resulting amount, never null. */ public static MonetaryAmount calculate(MonetaryAmount dividend, Rate discountRate, Rate growthRate) { Objects.requireNonNull(dividend, "dividend required"); Objects.requireNonNull(discountRate, "discountRate required"); Objects.requireNonNull(growthRate, "growthRate required"); return dividend.divide(discountRate.get().subtract(growthRate.get())); }
Example 4
Source File: StockPresentValue.java From javamoney-lib with Apache License 2.0 | 2 votes |
/** * Calculates the present value of a stock for constant growth. * * @param estimatedDividends the estimated dividends for next period * @param requiredRateOfReturn the required rate of return * @param growthRate the growth rate * @return the present value of the stock */ public static MonetaryAmount calculateForConstantGrowth(MonetaryAmount estimatedDividends, Rate requiredRateOfReturn, Rate growthRate) { return estimatedDividends.divide(requiredRateOfReturn.get().subtract(growthRate.get())); }
Example 5
Source File: ZeroCouponBondValue.java From javamoney-lib with Apache License 2.0 | 2 votes |
/** * Calculates the zero coupon bond value. * * @param face the face value of the bond * @param rate the rate * @param numberOfYearsToMaturity the number of years to maturity * @return the zero coupon bond value */ public static MonetaryAmount calculate(MonetaryAmount face, Rate rate, int numberOfYearsToMaturity) { return face.divide(BigDecimal.ONE.add(rate.get()).pow(numberOfYearsToMaturity)); }
Example 6
Source File: DividendsPerShare.java From javamoney-lib with Apache License 2.0 | 2 votes |
/** * Calculates the dividends per share. * * @param dividends the annual dividends paid * @param numberOfShares the number of shares outstanding * @return the dividends per share */ public static MonetaryAmount calculate(MonetaryAmount dividends, double numberOfShares) { return dividends.divide(numberOfShares); }
Example 7
Source File: PreferredStock.java From javamoney-lib with Apache License 2.0 | 2 votes |
/** * Calculates the preferred stock. * * @param dividend the dividend * @param discountRate the discount rate * @return the preferred stock */ public static MonetaryAmount calculate(MonetaryAmount dividend, Rate discountRate) { return dividend.divide(discountRate.get()); }
Example 8
Source File: BookValuePerShare.java From javamoney-lib with Apache License 2.0 | 2 votes |
/** * Calculates the per share value of a company based on its equity. * * @param equity the total common stockholder's equity * @param numberOfCommonShares the number of common shares * @return the book value per share */ public static MonetaryAmount calculate(MonetaryAmount equity, int numberOfCommonShares) { return equity.divide(numberOfCommonShares); }
Example 9
Source File: EarningsPerShare.java From javamoney-lib with Apache License 2.0 | 2 votes |
/** * Calculates the earnings per share. * * @param netIncome the company's net income * @param weightedAverageOfOutstandingShares the weighted average of outstanding shares of common stock * @return the earnings per share */ public static MonetaryAmount calculate(MonetaryAmount netIncome, double weightedAverageOfOutstandingShares) { return netIncome.divide(weightedAverageOfOutstandingShares); }
Example 10
Source File: DilutedEarningsPerShare.java From javamoney-lib with Apache License 2.0 | 2 votes |
/** * Calculates the diluted earnings per share. * * @param netIncome the firm's net income * @param averageShares the firm's average shares * @param otherConvertibleInstruments other convertible instruments * @return the diluted earnings per share */ public static MonetaryAmount calculate(MonetaryAmount netIncome, BigDecimal averageShares, BigDecimal otherConvertibleInstruments) { return netIncome.divide(averageShares.add(otherConvertibleInstruments)); }
Example 11
Source File: PresentValueOfPerpetuity.java From javamoney-lib with Apache License 2.0 | 2 votes |
/** * Performs the calculation. * * @param amount the first payment * @param rate The rate, not null. * @return the resulting amount, never null. */ public static MonetaryAmount calculate(MonetaryAmount amount, Rate rate) { Objects.requireNonNull(amount, "Amount required"); Objects.requireNonNull(rate, "Rate required"); return amount.divide(rate.get()); }
Example 12
Source File: PresentValue.java From javamoney-lib with Apache License 2.0 | 2 votes |
/** * Performs the calculation. * * @param amount the first payment * @param rateAndPeriods The rate and periods, not null. * @return the resulting amount, never null. */ public static MonetaryAmount calculate(MonetaryAmount amount, RateAndPeriods rateAndPeriods){ Objects.requireNonNull(amount, "Amount required"); Objects.requireNonNull(rateAndPeriods, "RateAndPeriods required"); return amount.divide(PresentValueFactor.calculate(rateAndPeriods)); }