javax.money.RoundingQueryBuilder Java Examples
The following examples show how to use
javax.money.RoundingQueryBuilder.
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: PresentValueContinuousCompoundingTest.java From javamoney-lib with Apache License 2.0 | 6 votes |
/** * Method: of(Rate rate, int periods) * * @throws Exception the exception */ @Test public void testOfAndApply() throws Exception { Money money = Money.of(100, "CHF"); MonetaryOperator rounding = Monetary.getRounding(RoundingQueryBuilder.of().setScale(2).set(RoundingMode.HALF_EVEN) .build()); assertEquals(Money.of(BigDecimal.valueOf(95.12), "CHF"), money.with(PresentValueContinuousCompounding.of(RateAndPeriods.of(0.05, 1))).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(90.48), "CHF"), money.with(PresentValueContinuousCompounding.of(RateAndPeriods.of(0.05, 2))).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(46.3), "CHF"), money.with(PresentValueContinuousCompounding.of(RateAndPeriods.of(0.07, 11))).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(100.00), "CHF"), money.with(PresentValueContinuousCompounding.of(RateAndPeriods.of(0.05, 0))).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(100.00), "CHF"), money.with(PresentValueContinuousCompounding.of(RateAndPeriods.of(-0.05, 0))).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(105.13), "CHF"), money.with(PresentValueContinuousCompounding.of(RateAndPeriods.of(-0.05, 1))).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(110.52), "CHF"), money.with(PresentValueContinuousCompounding.of(RateAndPeriods.of(-0.05, 2))).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(215.98), "CHF"), money.with(PresentValueContinuousCompounding.of(RateAndPeriods.of(-0.07, 11))).with(rounding)); }
Example #2
Source File: AmountsUseExtensionPoints.java From javamoney-examples with Apache License 2.0 | 6 votes |
public static void main(String... args){ MonetaryAmount amt = Money.of(1234.56234, "CHF"); ConsoleUtils.printDetails("Base", amt); ConsoleUtils.printDetails("10.5 %", amt.with(MonetaryOperators.percent(10.5))); ConsoleUtils.printDetails("10.5 o/oo", amt.with(MonetaryOperators.permil(10.5))); ConsoleUtils.printDetails("Major Part", amt.with(MonetaryOperators.majorPart())); ConsoleUtils.printDetails("Minor Part", amt.with(MonetaryOperators.minorPart())); ConsoleUtils.printDetails("1/Base (Reciprocal)", amt.with(MonetaryOperators.reciprocal())); System.out.println("Minor Part as long -> " + amt.query(MonetaryQueries.extractMinorPart())); System.out.println("Major Part as long -> " + amt.query(MonetaryQueries.extractMajorPart())); ConsoleUtils.printDetails("Rounded (default)", amt.with(Monetary.getDefaultRounding())); ConsoleUtils.printDetails("Rounded (DOWN, 1 fraction digit)", amt.with(Monetary.getRounding( RoundingQueryBuilder.of().set(RoundingMode.DOWN).setScale(1).build() ))); }
Example #3
Source File: AmountsUseExtensionPoints.java From javamoney-examples with Apache License 2.0 | 6 votes |
public static void main(String... args){ MonetaryAmount amt = Money.of(1234.56234, "CHF"); ConsoleUtils.printDetails("Base", amt); ConsoleUtils.printDetails("10.5 %", amt.with(MonetaryOperators.percent(10.5))); ConsoleUtils.printDetails("10.5 o/oo", amt.with(MonetaryOperators.permil(10.5))); ConsoleUtils.printDetails("Major Part", amt.with(MonetaryOperators.majorPart())); ConsoleUtils.printDetails("Minor Part", amt.with(MonetaryOperators.minorPart())); ConsoleUtils.printDetails("1/Base (Reciprocal)", amt.with(MonetaryOperators.reciprocal())); System.out.println("Minor Part as long -> " + amt.query(MonetaryQueries.extractMinorPart())); System.out.println("Major Part as long -> " + amt.query(MonetaryQueries.extractMajorPart())); ConsoleUtils.printDetails("Rounded (default)", amt.with(Monetary.getDefaultRounding())); ConsoleUtils.printDetails("Rounded (DOWN, 1 fraction digit)", amt.with(Monetary.getRounding( RoundingQueryBuilder.of().set(RoundingMode.DOWN).setScale(1).build() ))); }
Example #4
Source File: FutureValueTest.java From javamoney-lib with Apache License 2.0 | 5 votes |
/** * Method: of(Rate ratePerPeriod, int periods). * * @throws Exception the exception */ @Test public void testOfAndApply() throws Exception { Money money = Money.of(100, "CHF"); MonetaryOperator rounding = Monetary.getRounding(RoundingQueryBuilder.of().setScale(2).set(RoundingMode.HALF_EVEN) .build()); assertEquals(Money.of(BigDecimal.valueOf(105.00), "CHF"), money.with(FutureValue .of(RateAndPeriods.of(0.05, 1))).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(110.25), "CHF"), money.with(FutureValue.of(RateAndPeriods.of(0.05, 2))).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(210.49), "CHF"), money.with(FutureValue.of(RateAndPeriods.of(0.07, 11))).with(rounding)); }
Example #5
Source File: FutureValueTest.java From javamoney-lib with Apache License 2.0 | 5 votes |
/** * Method: calculate(MonetaryAmount amount, Rate rate, int periods) * * @throws Exception the exception */ @Test public void testCalculate() throws Exception { Money money = Money.of(100, "CHF"); MonetaryOperator rounding = Monetary.getRounding(RoundingQueryBuilder.of().setScale(2).set(RoundingMode.HALF_EVEN) .build()); assertEquals(Money.of(BigDecimal.valueOf(105.00), "CHF"), FutureValue.calculate(money, RateAndPeriods.of(0.05, 1)).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(110.25), "CHF"), FutureValue.calculate(money, RateAndPeriods.of(0.05, 2)).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(210.49), "CHF"), FutureValue.calculate(money, RateAndPeriods.of(0.07, 11)).with(rounding)); }
Example #6
Source File: FutureValueTest.java From javamoney-lib with Apache License 2.0 | 5 votes |
/** * Test formula. */ @Test public void testFormula() { Money money = Money.of(100, "CHF"); MonetaryOperator rounding = Monetary.getRounding(RoundingQueryBuilder.of().setScale(2).set(RoundingMode.HALF_EVEN) .build()); assertEquals(Money.of(BigDecimal.valueOf(105.00), "CHF"), FutureValue.calculate(money, RateAndPeriods.of(0.05, 1)).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(110.25), "CHF"), FutureValue.calculate(money, RateAndPeriods.of(0.05, 2)).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(210.49), "CHF"), FutureValue.calculate(money, RateAndPeriods.of(0.07, 11)).with(rounding)); }
Example #7
Source File: PresentValueContinuousCompoundingTest.java From javamoney-lib with Apache License 2.0 | 5 votes |
/** * Method: calculate(MonetaryAmount amount, Rate rate, int periods) * * @throws Exception the exception */ @Test public void testCalculate() throws Exception { Money money = Money.of(100, "CHF"); MonetaryOperator rounding = Monetary.getRounding(RoundingQueryBuilder.of().setScale(2).set(RoundingMode.HALF_EVEN) .build()); assertEquals(Money.of(BigDecimal.valueOf(95.12), "CHF"), PresentValueContinuousCompounding.calculate(money, RateAndPeriods.of(0.05, 1)).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(90.48), "CHF"), PresentValueContinuousCompounding.calculate(money, RateAndPeriods.of(0.05, 2)).with(rounding)); assertEquals(Money.of(BigDecimal.valueOf(46.3), "CHF"), PresentValueContinuousCompounding.calculate(money, RateAndPeriods.of(0.07, 11)).with(rounding)); }