Class UtilNumber

java.lang.Object
org.apache.ofbiz.base.util.UtilNumber

public final class UtilNumber extends Object
  • Field Details

  • Method Details

    • getBigDecimalScale

      public static int getBigDecimalScale(String file, String property)
      Method to get BigDecimal scale factor from a property
      Parameters:
      file - - Name of the property file
      property - - Name of the config property from ARITH_PROP_FILE (e.g., "invoice.decimals")
      Returns:
      int - Scale factor to pass to BigDecimal's methods. Defaults to DEFAULT_BD_SCALE (2)
    • getBigDecimalScale

      public static int getBigDecimalScale(String property)
      Method to get BigDecimal scale factor from a property. Use the default ARITH_PROP_FILE properties file
      Parameters:
      property - - Name of the config property from ARITH_PROP_FILE (e.g., "invoice.decimals")
      Returns:
      int - Scale factor to pass to BigDecimal's methods. Defaults to DEFAULT_BD_SCALE (2)
    • getBigDecimalRoundingMode

      @Deprecated public static int getBigDecimalRoundingMode(String file, String property)
      Deprecated.
      Method to get BigDecimal rounding mode from a property
      Parameters:
      file - - Name of the property file
      property - - Name of the config property from ARITH_PROP_FILE (e.g., "invoice.rounding")
      Returns:
      int - Rounding mode to pass to BigDecimal's methods. Defaults to BigDecimal.ROUND_HALF_UP
    • getBigDecimalRoundingMode

      @Deprecated public static int getBigDecimalRoundingMode(String property)
      Deprecated.
      Method to get BigDecimal rounding mode from a property. Use the default ARITH_PROP_FILE properties file
      Parameters:
      property - - Name of the config property from ARITH_PROP_FILE (e.g., "invoice.rounding")
      Returns:
      int - Rounding mode to pass to BigDecimal's methods. Defaults to BigDecimal.ROUND_HALF_UP
    • getRoundingMode

      public static RoundingMode getRoundingMode(String file, String property)
      Method to get BigDecimal rounding mode from a property
      Parameters:
      file - - Name of the property file
      property - - Name of the config property from ARITH_PROP_FILE (e.g., "invoice.rounding")
      Returns:
      RoundingMode - Rounding mode to pass to BigDecimal's methods. Defaults to DEFAULT_BD_ROUNDING_MODE (RoundingMode.HALF_UP)
    • getRoundingMode

      public static RoundingMode getRoundingMode(String property)
      Method to get BigDecimal rounding mode from a property. Use the default ARITH_PROP_FILE properties file
      Parameters:
      property - - Name of the config property from ARITH_PROP_FILE (e.g., "invoice.rounding")
      Returns:
      RoundingMode - Rounding mode to pass to BigDecimal's methods. Defaults to DEFAULT_BD_ROUNDING_MODE (RoundingMode.HALF_UP)
    • formatRuleBasedAmount

      public static String formatRuleBasedAmount(double amount, Locale locale)
      Method to format an amount using a custom rule set. Current rule sets available:
      Parameters:
      amount - - the amount to format
      locale - - the Locale
      Returns:
      formatted string or an empty string if there was an error
    • toPercentString

      @Deprecated public static String toPercentString(Number number, int scale, int roundingMode)
      Deprecated.
      Use toPercentString(Number number, int scale, RoundingMode roundingMode) instead
      Method to turn a number such as "0.9853" into a nicely formatted percent, "98.53%".
      Parameters:
      number - The number object to format
      scale - How many places after the decimal to include
      roundingMode - The BigDecimal rounding mode to apply
      Returns:
      The formatted string or "" if there were errors.
    • safeAdd

      public static BigDecimal safeAdd(BigDecimal left, BigDecimal right)
      A null-aware method for adding BigDecimal, but only for the right operand.
      Parameters:
      left - The number to add to
      right - The number being added; if null, then nothing will be added
      Returns:
      The result of the addition, or left if right is null.
    • getBigDecimal

      public static BigDecimal getBigDecimal(Map<String,?> context, String field, BigDecimal defaultValue)
      Resolve a BigDecimal for a given field present on context map and return default value if not present
      Parameters:
      context -
      field -
      defaultValue -
      Returns: