Class KiwiBigDecimals


  • public class KiwiBigDecimals
    extends Object
    Utilities for working with BigDecimal.

    Neither Guava (e.g. DoubleMath) nor Apache Commons (e.g. NumberUtils) contained these exact conversions when this was originally implemented. The Apache Commons NumberUtils does contain conversion methods that accept a default value for null input, or if zero is OK as the default.

    • Constructor Detail

      • KiwiBigDecimals

        public KiwiBigDecimals()
    • Method Detail

      • toDoubleOrNull

        public static Double toDoubleOrNull​(@Nullable
                                            BigDecimal value)
        Converts a nullable BigDecimal to a Double or returns null if the given value is null.
        Parameters:
        value - the BigDecimal or null
        Returns:
        converted Double or null
      • requireDouble

        public static double requireDouble​(@Nonnull
                                           BigDecimal value)
        Converts the given BigDecimal to a primitive double.
        Parameters:
        value - the non-null BigDecimal
        Returns:
        a primitive double
        Throws:
        IllegalArgumentException - if the given value is null