diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/expr/NumericConfig.java | 29 | ||||
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java | 25 |
2 files changed, 46 insertions, 8 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/expr/NumericConfig.java b/src/main/java/com/healthmarketscience/jackcess/expr/NumericConfig.java index 9ae09b3..f8fd51b 100644 --- a/src/main/java/com/healthmarketscience/jackcess/expr/NumericConfig.java +++ b/src/main/java/com/healthmarketscience/jackcess/expr/NumericConfig.java @@ -31,14 +31,39 @@ import java.util.Locale; public class NumericConfig { public static final NumericConfig US_NUMERIC_CONFIG = new NumericConfig( - Locale.US); + 2, true, false, 3, Locale.US); + private final int _numDecDigits; + private final boolean _incLeadingDigit; + private final boolean _useNegParens; + private final int _numGroupDigits; private final DecimalFormatSymbols _symbols; - public NumericConfig(Locale locale) { + public NumericConfig(int numDecDigits, boolean incLeadingDigit, + boolean useNegParens, int numGroupDigits, Locale locale) { + _numDecDigits = numDecDigits; + _incLeadingDigit = incLeadingDigit; + _useNegParens = useNegParens; + _numGroupDigits = numGroupDigits; _symbols = DecimalFormatSymbols.getInstance(locale); } + public int getNumDecimalDigits() { + return _numDecDigits; + } + + public boolean includeLeadingDigit() { + return _incLeadingDigit; + } + + public boolean useParensForNegatives() { + return _useNegParens; + } + + public int getNumGroupingDigits() { + return _numGroupDigits; + } + public DecimalFormatSymbols getDecimalFormatSymbols() { return _symbols; } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java index 687edf9..2f71718 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java @@ -27,6 +27,7 @@ import com.healthmarketscience.jackcess.expr.EvalContext; import com.healthmarketscience.jackcess.expr.EvalException; import com.healthmarketscience.jackcess.expr.Function; import com.healthmarketscience.jackcess.expr.FunctionLookup; +import com.healthmarketscience.jackcess.expr.NumericConfig; import com.healthmarketscience.jackcess.expr.Value; import com.healthmarketscience.jackcess.impl.DatabaseImpl; import com.healthmarketscience.jackcess.impl.NumberFormatter; @@ -287,10 +288,16 @@ public class DefaultFunctions return ValueSupport.NULL_VAL; } - int numDecDigits = getOptionalIntParam(ctx, params, 1, 2, -1); - boolean incLeadDigit = getOptionalTriStateBoolean(ctx, params, 2, true); - boolean negParens = getOptionalTriStateBoolean(ctx, params, 3, false); - boolean groupDigits = getOptionalTriStateBoolean(ctx, params, 4, true); + NumericConfig cfg = ctx.getNumericConfig(); + int numDecDigits = getOptionalIntParam( + ctx, params, 1, cfg.getNumDecimalDigits(), -1); + boolean incLeadDigit = getOptionalTriStateBoolean( + ctx, params, 2, cfg.includeLeadingDigit()); + boolean negParens = getOptionalTriStateBoolean( + ctx, params, 3, cfg.useParensForNegatives()); + int numGroupDigits = cfg.getNumGroupingDigits(); + boolean groupDigits = getOptionalTriStateBoolean( + ctx, params, 4, (numGroupDigits > 0)); StringBuilder fmt = new StringBuilder(); @@ -308,8 +315,14 @@ public class DefaultFunctions // Note, DecimalFormat rounding mode uses HALF_EVEN by default DecimalFormat df = new DecimalFormat( - fmt.toString(), ctx.getNumericConfig().getDecimalFormatSymbols()); - df.setGroupingUsed(groupDigits); + fmt.toString(), cfg.getDecimalFormatSymbols()); + if(groupDigits) { + df.setGroupingUsed(true); + df.setGroupingSize(numGroupDigits); + } else { + df.setGroupingUsed(false); + df.setGroupingSize(numGroupDigits); + } return ValueSupport.toValue(df.format(param1.getAsBigDecimal(ctx))); } |