Class BigDecComponents

java.lang.Object
com.singularsys.jep.ComponentSet
com.singularsys.jep.bigdecimal.BigDecComponents
All Implemented Interfaces:
FixedPrecisionFunctionI

public class BigDecComponents extends ComponentSet implements FixedPrecisionFunctionI
A set of components for working with big decimal numbers.

It can be set up in a number of ways:

  • With unlimited precision, some operators like division will fail
  • Using a MathContext specifying the number of significant figures, and rounding mode.
  • Fixed-point setup, with a specified number of decimal places to use for all results.
In addition the components can be setup to allow addition and comparison of strings. Comparison and logical operators also work with Booleans.
  • Field Details

    • mc

      protected MathContext mc
    • scale

      protected int scale
    • allowStrings

      protected boolean allowStrings
  • Constructor Details

    • BigDecComponents

      public BigDecComponents()
      Constructs the class using the MathContext.UNLIMITED for unlimited precision arithmetic.
    • BigDecComponents

      public BigDecComponents(MathContext mc)
      Constructs the class with the specific math context. The math context is passed the number factory, function table, and operator table constructors.
      Parameters:
      mc - the math context for the components.
    • BigDecComponents

      public BigDecComponents(int scale)
      Fixed precision setup, with a specified number of decimal places. Uses unlimited precision with the rounding mode half-even.
      Parameters:
      scale - number of decimal digits should be greater or equal to zero.
      Since:
      Jep 4.1
    • BigDecComponents

      public BigDecComponents(MathContext mc, int scale, boolean allowStrings)
      Fixed precision setup with a specific MathContext and optional string support.
      Parameters:
      mc - specifying the precision and rounding mode used.
      scale - number of decimal digits should be greater or equal to zero.
      allowStrings - whether string are allowed
      Since:
      Jep 4.1
    • BigDecComponents

      public BigDecComponents(MathContext mc, boolean allowStrings)
      Setup with string support
      Parameters:
      mc - The mathContext to use
      allowStrings - whether string are allowed
  • Method Details

    • getMathContext

      public MathContext getMathContext()
    • setMathContext

      public void setMathContext(MathContext mc)
    • setAllowStrings

      public void setAllowStrings(boolean allowStrings)
      Sets whether BigDecimals and strings can be used together.
      Parameters:
      allowStrings -
      Since:
      3.4.0
    • getAllowStrings

      public boolean getAllowStrings()
      Whether string are allowed
      Returns:
      true is string can be used
      Since:
      3.4.0
    • setDecimalPlaces

      public void setDecimalPlaces(int scale)
      Set the scale used for fixed precision numbers
      Specified by:
      setDecimalPlaces in interface FixedPrecisionFunctionI
      Parameters:
      scale - number of decimal digits should be greater or equal to zero.
      Since:
      Jep 4.1
    • getDecimalPlaces

      public int getDecimalPlaces()
      Get the scale used for fixed precision numbers
      Specified by:
      getDecimalPlaces in interface FixedPrecisionFunctionI
      Returns:
      number of decimal digits or -1 if not using fixed precision
      Since:
      Jep 4.1