Package org.apache.ofbiz.base.util
Class UtilNumber
java.lang.Object
org.apache.ofbiz.base.util.UtilNumber
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic String
formatRuleBasedAmount
(double amount, Locale locale) Method to format an amount using a custom rule set.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 presentstatic int
getBigDecimalRoundingMode
(String property) Deprecated.static int
getBigDecimalRoundingMode
(String file, String property) Deprecated.UsegetRoundingMode(String, String)
insteadstatic int
getBigDecimalScale
(String property) Method to get BigDecimal scale factor from a property.static int
getBigDecimalScale
(String file, String property) Method to get BigDecimal scale factor from a propertystatic RoundingMode
getRoundingMode
(String property) Method to get BigDecimal rounding mode from a property.static RoundingMode
getRoundingMode
(String file, String property) Method to get BigDecimal rounding mode from a propertystatic BigDecimal
safeAdd
(BigDecimal left, BigDecimal right) A null-aware method for adding BigDecimal, but only for the right operand.static String
toPercentString
(Number number, int scale, int roundingMode) Deprecated.UsetoPercentString(Number number, int scale, RoundingMode roundingMode)
instead
-
Field Details
-
RULE_SET_EN_IN
- See Also:
-
-
Method Details
-
getBigDecimalScale
Method to get BigDecimal scale factor from a property- Parameters:
file
- - Name of the property fileproperty
- - 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
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.UsegetRoundingMode(String, String)
insteadMethod to get BigDecimal rounding mode from a property- Parameters:
file
- - Name of the property fileproperty
- - 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.UsegetRoundingMode(String)
insteadMethod 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
Method to get BigDecimal rounding mode from a property- Parameters:
file
- - Name of the property fileproperty
- - 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
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
Method to format an amount using a custom rule set. Current rule sets available:- Parameters:
amount
- - the amount to formatlocale
- - the Locale- Returns:
- formatted string or an empty string if there was an error
-
toPercentString
Deprecated.UsetoPercentString(Number number, int scale, RoundingMode roundingMode)
insteadMethod to turn a number such as "0.9853" into a nicely formatted percent, "98.53%".- Parameters:
number
- The number object to formatscale
- How many places after the decimal to includeroundingMode
- The BigDecimal rounding mode to apply- Returns:
- The formatted string or "" if there were errors.
-
safeAdd
A null-aware method for adding BigDecimal, but only for the right operand.- Parameters:
left
- The number to add toright
- 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:
-
getRoundingMode(String)
instead