org.ofbiz.base.util
Class UtilNumber

java.lang.Object
  extended by org.ofbiz.base.util.UtilNumber

public class UtilNumber
extends java.lang.Object


Field Summary
static java.lang.String module
           
static java.util.HashMap<java.util.Locale,java.lang.String> rbnfRuleSets
           
static java.lang.String ruleSet_en_US
           
 
Constructor Summary
UtilNumber()
           
 
Method Summary
static java.lang.String formatRuleBasedAmount(double amount, java.lang.String rule, java.util.Locale locale)
          Method to format an amount using a custom rule set.
static int getBigDecimalRoundingMode(java.lang.String property)
          As above, but use the default properties file
static int getBigDecimalRoundingMode(java.lang.String file, java.lang.String property)
          Method to get BigDecimal rounding mode from a property
static int getBigDecimalScale(java.lang.String property)
          As above, but use the default properties file
static int getBigDecimalScale(java.lang.String file, java.lang.String property)
          Method to get BigDecimal scale factor from a property
static int roundingModeFromString(java.lang.String value)
          Method to get the BigDecimal rounding mode int value from a string name.
static java.lang.String toPercentString(java.lang.Number number, int scale, int roundingMode)
          Method to turn a number such as "0.9853" into a nicely formatted percent, "98.53%".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

module

public static java.lang.String module

ruleSet_en_US

public static final java.lang.String ruleSet_en_US
See Also:
Constant Field Values

rbnfRuleSets

public static java.util.HashMap<java.util.Locale,java.lang.String> rbnfRuleSets
Constructor Detail

UtilNumber

public UtilNumber()
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 file
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)

getBigDecimalScale

public static int getBigDecimalScale(java.lang.String property)
As above, but use the default properties file


getBigDecimalRoundingMode

public static int getBigDecimalRoundingMode(java.lang.String file,
                                            java.lang.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 arithmeticPropertiesFile (e.g., "invoice.rounding")
Returns:
int - Rounding mode to pass to BigDecimal's methods. Defaults to DEFAULT_BD_ROUNDING_MODE (BigDecimal.ROUND_HALF_UP)

getBigDecimalRoundingMode

public static int getBigDecimalRoundingMode(java.lang.String property)
As above, but use the default properties file


roundingModeFromString

public static int roundingModeFromString(java.lang.String value)
Method to get the BigDecimal rounding mode int value from a string name.

Parameters:
value - - The name of the mode (e.g., "ROUND_HALF_UP")
Returns:
int - The int value of the mode (e.g, BigDecimal.ROUND_HALF_UP) or -1 if the input was bad.

formatRuleBasedAmount

public static java.lang.String formatRuleBasedAmount(double amount,
                                                     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 format
rule - - 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

public static java.lang.String toPercentString(java.lang.Number number,
                                               int scale,
                                               int roundingMode)
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.