/** * Converts a percent value into a decimal fraction i.e. 34 % to 0.34 * Effectively this is {@code this / 100} * * @return a decimal representation fo the given percent value. */ @Nonnull @CheckReturnValue public Amount asDecimal() { return divideBy(ONE_HUNDRED); }
/** * Returns the ratio in percent from <tt>this</tt> to <tt>other</tt>. * This is equivalent to {@code this / other * 100} * * @param other the base to compute the percentage from. * @return an <tt>Amount</tt> representing the ratio between <tt>this</tt> and <tt>other</tt> * or <tt>NOTHING</tt> if either of both is empty. */ @Nonnull @CheckReturnValue public Amount percentageOf(@Nullable Amount other) { return divideBy(other).toPercent(); }
/** * Returns the increase in percent of <tt>this</tt> over <tt>other</tt>. * This is equivalent to {@code ((this / other) - 1) * 100} * * @param other the base to compute the increase from. * @return an <tt>Amount</tt> representing the percentage increase between <tt>this</tt> and <tt>other</tt> * or <tt>NOTHING</tt> if either of both is empty. */ @Nonnull @CheckReturnValue public Amount percentageDifferenceOf(@Nonnull Amount other) { return divideBy(other).subtract(ONE).toPercent(); }
/** * 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)); }