Class ParseBigDecimal

java.lang.Object
org.supercsv.cellprocessor.CellProcessorAdaptor
org.supercsv.cellprocessor.ParseBigDecimal
All Implemented Interfaces:
CellProcessor, StringCellProcessor

public class ParseBigDecimal extends CellProcessorAdaptor implements StringCellProcessor
Convert a String to a BigDecimal. It uses the String constructor of BigDecimal (new BigDecimal("0.1")) as it yields predictable results (see BigDecimal).

If the data uses a character other than "." as a decimal separator (Germany uses "," for example), then use the constructor that accepts a DecimalFormatSymbols object, as it will convert the character to a "." before creating the BigDecimal. Likewise if the data contains a grouping separator (Germany uses "." for example) then supplying a DecimalFormatSymbols object will allow grouping separators to be removed before parsing.

Since:
1.30
Author:
Kasper B. Graversen, James Bassett
  • Field Summary

    Fields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor

    next
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new ParseBigDecimal processor, which converts a String to a BigDecimal.
    Constructs a new ParseBigDecimal processor, which converts a String to a BigDecimal using the supplied DecimalFormatSymbols object to convert any decimal separator to a "." before creating the BigDecimal.
    Constructs a new ParseBigDecimal processor, which converts a String to a BigDecimal using the supplied DecimalFormatSymbols object to convert any decimal separator to a "." before creating the BigDecimal, then calls the next processor in the chain.
    Constructs a new ParseBigDecimal processor, which converts a String to a BigDecimal then calls the next processor in the chain.
  • Method Summary

    Modifier and Type
    Method
    Description
    execute(Object value, CsvContext context)
    This method is invoked by the framework when the processor needs to process data or check constraints.

    Methods inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor

    toString, validateInputNotNull

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ParseBigDecimal

      public ParseBigDecimal()
      Constructs a new ParseBigDecimal processor, which converts a String to a BigDecimal.
    • ParseBigDecimal

      public ParseBigDecimal(DecimalFormatSymbols symbols)
      Constructs a new ParseBigDecimal processor, which converts a String to a BigDecimal using the supplied DecimalFormatSymbols object to convert any decimal separator to a "." before creating the BigDecimal.
      Parameters:
      symbols - the decimal format symbols, containing the decimal separator
      Throws:
      NullPointerException - if symbols is null
    • ParseBigDecimal

      public ParseBigDecimal(CellProcessor next)
      Constructs a new ParseBigDecimal processor, which converts a String to a BigDecimal then calls the next processor in the chain.
      Parameters:
      next - the next processor in the chain
      Throws:
      NullPointerException - if next is null
    • ParseBigDecimal

      public ParseBigDecimal(DecimalFormatSymbols symbols, CellProcessor next)
      Constructs a new ParseBigDecimal processor, which converts a String to a BigDecimal using the supplied DecimalFormatSymbols object to convert any decimal separator to a "." before creating the BigDecimal, then calls the next processor in the chain.
      Parameters:
      symbols - the decimal format symbols, containing the decimal separator
      next - the next processor in the chain
      Throws:
      NullPointerException - if symbols or next is null
  • Method Details

    • execute

      public Object execute(Object value, CsvContext context)
      This method is invoked by the framework when the processor needs to process data or check constraints.
      Specified by:
      execute in interface CellProcessor
      Parameters:
      value - the value to be processed
      context - the CSV context
      Returns:
      the result of cell processor execution
      Throws:
      SuperCsvCellProcessorException - if value is null, isn't a String, or can't be parsed as a BigDecimal