java.lang.Object
com.northconcepts.datapipeline.transform.format.Rounder

public class Rounder extends Object
Rounds numbers to a number of decimal places using a Rounder.RoundingPolicy.
  • Constructor Details

    • Rounder

      public Rounder(Rounder.RoundingPolicy roundPolicy, int decimalPlaces)
      Creates a rounder; a negative decimalPlaces rounds to the left of the decimal point (for example, -2 rounds to hundreds).
  • Method Details

    • getDecimalPlaces

      public int getDecimalPlaces()
      Returns the number of decimal places to round to; negative values round to the left of the decimal point.
    • setDecimalPlaces

      public Rounder setDecimalPlaces(int decimalPlaces)
      Sets the number of decimal places to round to; negative values round to the left of the decimal point.
    • getRoundPolicy

      public Rounder.RoundingPolicy getRoundPolicy()
    • setRoundPolicy

      public Rounder setRoundPolicy(Rounder.RoundingPolicy roundPolicy)
    • apply

      public double apply(double value)
      Rounds the value in double arithmetic; the UNNECESSARY policy returns it unchanged.
    • apply

      public BigDecimal apply(BigDecimal value)
      Returns the value with its scale set to the decimal places using this policy, or null for null; HALF_ODD is not supported.
    • apply

      public BigInteger apply(BigInteger value)
      Rounds the value as a BigDecimal, so only negative decimal places change it; returns null for null.
    • toString

      public String toString()
      Overrides:
      toString in class Object