/** * Negates <tt>this</tt> amount and returns the new amount. * * @return an <tt>Amount</tt> representing the negated <tt>Amount</tt>. If <tt>this</tt> is empty, <tt>NOTHING</tt> * is returned. */ public Amount negate() { return times(MINUS_ONE); }
/** * Converts a given decimal fraction into a percent value i.e. 0.34 to 34 %. * Effectively this is {@code this * 100} * * @return a percentage representation of the given decimal value. */ @Nonnull @CheckReturnValue public Amount toPercent() { return this.times(ONE_HUNDRED); }
/** * Increases this number by the given amount in percent. If <tt>increase</tt> is 18 and the value of this is 100, * the result would by 118. * * @param increase the percent value by which the value of this will be increased * @return <tt>NOTHING</tt> if <tt>this</tt> is empty, {@code this * (1 + increase / 100)} otherwise */ @Nonnull @CheckReturnValue public Amount increasePercent(@Nonnull Amount increase) { return times(ONE.add(increase.asDecimal())); }
/** * Decreases this number by the given amount in percent. If <tt>decrease</tt> is 10 and the value of this is 100, * the result would by 90. * * @param decrease the percent value by which the value of this will be decreased * @return <tt>NOTHING</tt> if <tt>this</tt> is empty, {@code this * (1 - increase / 100)} otherwise */ @Nonnull @CheckReturnValue public Amount decreasePercent(@Nonnull Amount decrease) { return times(ONE.subtract(decrease.asDecimal())); }
/** * Used to multiply two percentages, like two discounts as if they where applied after each other. * <p> * This can be used to compute the effective discount if two discounts like 15% and 5% are applied after * each other. The result would be {@code (15 + 5) - (15 * 5 / 100)} which is <tt>19,25 %</tt> * * @param percent the second percent value which would be applied after this percent value. * @return the effective percent value after both percentages would have been applied or <tt>NOTHING</tt> if * <tt>this</tt> is empty. */ @Nonnull @CheckReturnValue public Amount multiplyPercent(@Nonnull Amount percent) { return add(percent).subtract(this.times(percent).divideBy(ONE_HUNDRED)); }