org.ojalgo.type.context
Class NumberContext
java.lang.Object
org.ojalgo.type.context.TypeContext<Number>
org.ojalgo.type.context.NumberContext
- All Implemented Interfaces:
- Serializable
public final class NumberContext
- extends TypeContext<Number>
Think of this as a MathContext that specifies both precision and
scale. Numeric data types (non-integers) in databases are specified using
precison and scale. While doing maths the precision is all that matters, but
before sending a number to a database, or printing/displaying it, rounding to
a specified scale is desireable.
The enforce methods first enforce the precision and then set the scale.
It is possible that this will create a number with trailing zeros and more
digits than the precision allows. It is also possible to define a context
with a scale that is larger than the precision. This is NOT how precision and
scale is used with numeric types in databases.
- Author:
- apete
- See Also:
- Serialized Form
NumberContext
public NumberContext()
NumberContext
public NumberContext(Format aFormat,
int aPrecision,
int aScale,
RoundingMode aMode)
getCurrency
public static NumberContext getCurrency(Locale aLocale)
getGeneral
public static NumberContext getGeneral(int aScale)
getGeneral
public static NumberContext getGeneral(int aPrecision,
int aScale)
getGeneral
public static NumberContext getGeneral(MathContext aContext)
getInteger
public static NumberContext getInteger(Locale aLocale)
getPercent
public static NumberContext getPercent(Locale aLocale)
enforce
public BigDecimal enforce(BigDecimal aNmbr)
enforce
public ComplexNumber enforce(ComplexNumber aNmbr)
enforce
public double enforce(double aNmbr)
enforce
public Number enforce(Number anObject)
- Specified by:
enforce in class TypeContext<Number>
enforce
public RationalNumber enforce(RationalNumber aNmbr)
getError
public double getError()
getFunction
public <N extends Number> UnaryFunction<N> getFunction()
getMathContext
public MathContext getMathContext()
getPrecision
public int getPrecision()
getRoundingMode
public RoundingMode getRoundingMode()
getScale
public int getScale()
hashCode
public int hashCode()
- Overrides:
hashCode in class TypeContext<Number>
setFormat
public void setFormat(NumberStyle aStyle,
Locale aLocale)
setRoundingMode
public final void setRoundingMode(RoundingMode aMode)
toBigDecimal
public BigDecimal toBigDecimal(double aNmbr)
toLocalizedPattern
public String toLocalizedPattern()
- Works with
DecimalFormat and NumberContext.FormatPattern implementations.
In other cases it returns null.
toPattern
public String toPattern()
- Works with
DecimalFormat and NumberContext.FormatPattern implementations.
In other cases it returns null.