Package org.apache.ofbiz.base.util
Class UtilNumber
- java.lang.Object
-
- org.apache.ofbiz.base.util.UtilNumber
-
public final class UtilNumber extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
module
static java.lang.String
ruleSet_en_IN
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.String
formatRuleBasedAmount(double amount, java.lang.String ruleSet, java.lang.String rule, java.util.Locale locale)
Method to format an amount using a custom rule set.static java.lang.String
formatRuleBasedAmount(double amount, java.util.Locale locale)
Method to format an amount using a custom rule set.static int
getBigDecimalRoundingMode(java.lang.String property)
Deprecated.UsegetRoundingMode(String)
insteadstatic int
getBigDecimalRoundingMode(java.lang.String file, java.lang.String property)
Deprecated.UsegetRoundingMode(String,String)
insteadstatic int
getBigDecimalScale(java.lang.String property)
Method to get BigDecimal scale factor from a property.static int
getBigDecimalScale(java.lang.String file, java.lang.String property)
Method to get BigDecimal scale factor from a propertystatic java.math.RoundingMode
getRoundingMode(java.lang.String property)
Method to get BigDecimal rounding mode from a property.static java.math.RoundingMode
getRoundingMode(java.lang.String file, java.lang.String property)
Method to get BigDecimal rounding mode from a propertystatic java.math.RoundingMode
roundingModeFromString(java.lang.String value)
Method to get the RoundingMode rounding mode int value from a string name.static java.math.BigDecimal
safeAdd(java.math.BigDecimal left, java.math.BigDecimal right)
A null-aware method for adding BigDecimal, but only for the right operand.static java.lang.String
toPercentString(java.lang.Number number, int scale, int roundingMode)
Deprecated.static java.lang.String
toPercentString(java.lang.Number number, int scale, java.math.RoundingMode roundingMode)
Method to turn a number such as "0.9853" into a nicely formatted percent, "98.53%".
-
-
-
Field Detail
-
module
public static final java.lang.String module
-
ruleSet_en_IN
public static final java.lang.String ruleSet_en_IN
- See Also:
- Constant Field Values
-
-
Method Detail
-
getBigDecimalScale
public static int getBigDecimalScale(java.lang.String file, java.lang.String property)
Method to get BigDecimal scale factor from a property- Parameters:
file
- - Name of the property fileproperty
- - Name of the config property from arithmeticPropertiesFile (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(java.lang.String property)
Method to get BigDecimal scale factor from a property. Use the default arithmeticPropertiesFile properties file- Parameters:
property
- - Name of the config property from arithmeticPropertiesFile (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(java.lang.String file, java.lang.String property)
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 arithmeticPropertiesFile (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(java.lang.String property)
Deprecated.UsegetRoundingMode(String)
insteadMethod to get BigDecimal rounding mode from a property. Use the default arithmeticPropertiesFile properties file- Parameters:
property
- - Name of the config property from arithmeticPropertiesFile (e.g., "invoice.rounding")- Returns:
- int - Rounding mode to pass to BigDecimal's methods. Defaults to BigDecimal.ROUND_HALF_UP
-
getRoundingMode
public static java.math.RoundingMode getRoundingMode(java.lang.String file, java.lang.String property)
Method to get BigDecimal rounding mode from a property- Parameters:
file
- - Name of the property fileproperty
- - Name of the config property from arithmeticPropertiesFile (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 java.math.RoundingMode getRoundingMode(java.lang.String property)
Method to get BigDecimal rounding mode from a property. Use the default arithmeticPropertiesFile properties file- Parameters:
property
- - Name of the config property from arithmeticPropertiesFile (e.g., "invoice.rounding")- Returns:
- RoundingMode - Rounding mode to pass to BigDecimal's methods. Defaults to DEFAULT_BD_ROUNDING_MODE (RoundingMode.HALF_UP)
-
roundingModeFromString
public static java.math.RoundingMode roundingModeFromString(java.lang.String value)
Method to get the RoundingMode rounding mode int value from a string name.- Parameters:
value
- - The name of the mode (e.g., "ROUND_HALF_UP")- Returns:
- RoundingMode - The rounding mode value of the mode (e.g, RoundingMode.HALF_UP) or null if the input was bad.
-
formatRuleBasedAmount
public static java.lang.String formatRuleBasedAmount(double amount, java.util.Locale locale)
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
-
formatRuleBasedAmount
public static java.lang.String formatRuleBasedAmount(double amount, java.lang.String ruleSet, java.lang.String rule, java.util.Locale locale)
Method to format an amount using a custom rule set. Current rule sets available: en_US %dollars-and-cents - 1,225.25 becomes "one thousand two hundred twenty five dollars and twenty five cents" (useful for checks) %dollars-and-hundreths - 1,225.25 becomes "one thousand two hundred twenty five and 25/00" (alternate for checks)- Parameters:
amount
- - the amount to formatruleSet
- - ruleSet to userule
- - the name of the rule set to use (e.g., %dollars-and-hundredths)locale
- - the Locale- Returns:
- formatted string or an empty string if there was an error
-
toPercentString
@Deprecated public static java.lang.String toPercentString(java.lang.Number number, int scale, int roundingMode)
Deprecated.Method 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.
-
toPercentString
public static java.lang.String toPercentString(java.lang.Number number, int scale, java.math.RoundingMode roundingMode)
Method 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 RoundingMode rounding mode to apply- Returns:
- The formatted string or "" if there were errors.
-
safeAdd
public static java.math.BigDecimal safeAdd(java.math.BigDecimal left, java.math.BigDecimal right)
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.
-
-