Top Description Fields Constructors Methods
org.javamoney.moneta.function

pack-priv final Class PercentOperator

extends Object
implements MonetaryOperator
Class Inheritance
All Implemented Interfaces
javax.money.MonetaryOperator
Static Imports
java.text.NumberFormat.getPercentInstance

This class allows to extract the percentage of a MonetaryAmount instance.
Author
Werner Keil
Version
0.5
See Also
Wikipedia: Percentage

Field Summary

Modifier and TypeField and Description
private static final BigDecimal
private final BigDecimal

Constructor Summary

AccessConstructor and Description
pack-priv
PercentOperator(final BigDecimal decimal)

Access the shared instance of PercentOperator for use.

Method Summary

Modifier and TypeMethod and Description
public MonetaryAmount

Returns:

the percent result of the amount, never null
apply
(MonetaryAmount amount)

Implements javax.money.MonetaryOperator.apply.

Gets the percentage of the amount.

private static BigDecimal

Returns:

java.math.BigDecimal
calcPercent
(BigDecimal
java.math.BigDecimal
decimal
)

Calculate a BigDecimal value for a Percent e.g. "3" (3 percent) will generate .03

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

ONE_HUNDREDback to summary
private static final BigDecimal ONE_HUNDRED
percentValueback to summary
private final BigDecimal percentValue

Constructor Detail

PercentOperatorback to summary
pack-priv PercentOperator(final BigDecimal decimal)

Access the shared instance of PercentOperator for use.

Method Detail

applyback to summary
public MonetaryAmount apply(MonetaryAmount amount)

Implements javax.money.MonetaryOperator.apply.

Gets the percentage of the amount.

This returns the monetary amount in percent. For example, for 10% 'EUR 2.35' will return 0.235.

This is returned as a MonetaryAmount.

Returns:MonetaryAmount

the percent result of the amount, never null

Annotations
@Override
calcPercentback to summary
private static BigDecimal calcPercent(BigDecimal decimal)

Calculate a BigDecimal value for a Percent e.g. "3" (3 percent) will generate .03

Parameters
decimal:BigDecimal

java.math.BigDecimal

Returns:BigDecimal

java.math.BigDecimal

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override