public final class Percentage extends Object implements Comparable<Percentage>
A number has three standard representations in finance:
| Modifier and Type | Field and Description |
|---|---|
static Percentage |
ZERO
A percentage of zero.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Percentage other)
Compares this instance to another.
|
boolean |
equals(Object obj)
Checks if this instance equals another.
|
static Percentage |
fromBasisPoints(BasisPoints basisPoints)
Obtains an instance from a basis points value, where 70bps will create an instance representing 0.7%.
|
static Percentage |
fromDecimalForm(Decimal decimal)
Obtains an instance from mathematical decimal form, where 0.007 will create an instance representing 0.7%.
|
static Percentage |
fromDecimalForm(double decimal)
Obtains an instance from mathematical decimal form, where 0.007 will create an instance representing 0.7%.
|
int |
hashCode()
Returns a suitable hash code.
|
Percentage |
map(UnaryOperator<Decimal> mapper)
Applies an operation to the value.
|
Percentage |
minus(Percentage other)
Returns a percentage equal to the this percentage minus the other one.
|
static Percentage |
of(Decimal percentage)
Obtains an instance from a percentage value.
|
static Percentage |
of(double percentage)
Obtains an instance from a percentage value.
|
static Percentage |
parse(String str)
Parses a percentage.
|
Percentage |
plus(Percentage other)
Returns a percentage equal to the this percentage plus the other one.
|
BasisPoints |
toBasisPoints()
Converts this percentage to the equivalent basis points.
|
Decimal |
toDecimalForm()
Converts this percentage to mathematical decimal form.
|
String |
toString()
Returns the formal string representation, '{value}%'.
|
Decimal |
valuePercent()
Gets the value in percentage form as a
Decimal. |
public static final Percentage ZERO
public static Percentage of(double percentage)
percentage - the percentage valuepublic static Percentage of(Decimal percentage)
percentage - the percentage valuepublic static Percentage fromDecimalForm(double decimal)
decimal - the mathematical decimal valuepublic static Percentage fromDecimalForm(Decimal decimal)
decimal - the mathematical decimal valuepublic static Percentage fromBasisPoints(BasisPoints basisPoints)
basisPoints - the basis points valuepublic static Percentage parse(String str)
The percentage may be suffixed by '%' or 'pct'.
str - the percentage stringpublic Decimal valuePercent()
Decimal.
A value of 1.5% will return 1.5.
public Decimal toDecimalForm()
A value of 1.5% will return 0.015.
public BasisPoints toBasisPoints()
A value of 1.5% will return 150bps.
public Percentage plus(Percentage other)
other - the other percentagepublic Percentage minus(Percentage other)
other - the other percentagepublic Percentage map(UnaryOperator<Decimal> mapper)
This is generally used to apply a mathematical operation to the value. For example, the operator could multiply the value by a constant, or take the inverse.
abs = base.map(value -> value.abs());
mapper - the operator to be applied to the amountpublic int compareTo(Percentage other)
compareTo in interface Comparable<Percentage>other - the other instancepublic boolean equals(Object obj)
public int hashCode()
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.