public class NumericConfig
{
public static final NumericConfig US_NUMERIC_CONFIG = new NumericConfig(
- 2, true, false, 3, Locale.US);
+ 2, true, false, true, 3, Locale.US);
private final int _numDecDigits;
private final boolean _incLeadingDigit;
private final boolean _useNegParens;
+ private final boolean _useNegCurrencyParens;
private final int _numGroupDigits;
private final DecimalFormatSymbols _symbols;
public NumericConfig(int numDecDigits, boolean incLeadingDigit,
- boolean useNegParens, int numGroupDigits, Locale locale) {
+ boolean useNegParens, boolean useNegCurrencyParens,
+ int numGroupDigits, Locale locale) {
_numDecDigits = numDecDigits;
_incLeadingDigit = incLeadingDigit;
_useNegParens = useNegParens;
+ _useNegCurrencyParens = useNegCurrencyParens;
_numGroupDigits = numGroupDigits;
_symbols = DecimalFormatSymbols.getInstance(locale);
}
return _useNegParens;
}
+ public boolean useParensForCurrencyNegatives() {
+ return _useNegCurrencyParens;
+ }
+
public int getNumGroupingDigits() {
return _numGroupDigits;
}
ctx, params, 1, cfg.getNumDecimalDigits(), -1);
boolean incLeadDigit = getOptionalTriStateBoolean(
ctx, params, 2, cfg.includeLeadingDigit());
+ boolean defNegParens = (isCurrency ? cfg.useParensForCurrencyNegatives() :
+ cfg.useParensForNegatives());
boolean negParens = getOptionalTriStateBoolean(
- ctx, params, 3, cfg.useParensForNegatives());
+ ctx, params, 3, defNegParens);
int numGroupDigits = cfg.getNumGroupingDigits();
boolean groupDigits = getOptionalTriStateBoolean(
ctx, params, 4, (numGroupDigits > 0));
fmt.append("#,");
DefaultTextFunctions.nchars(fmt, numGroupDigits - 1, '#');
}
-
+
fmt.append(incLeadDigit ? "0" : "#");
if(numDecDigits > 0) {
fmt.append(".");
*
* @author James Ahlborn
*/
-public class FormatUtil
+public class FormatUtil
{
private static final Map<String,Fmt> PREDEF_FMTS = new HashMap<String,Fmt>();
PREDEF_FMTS.put("Short Time",
new PredefDateFmt(TemporalConfig.Type.SHORT_TIME));
+ PREDEF_FMTS.put("True/False", new PredefBoolFmt("True", "False"));
+ PREDEF_FMTS.put("Yes/No", new PredefBoolFmt("Yes", "No"));
+ PREDEF_FMTS.put("On/Off", new PredefBoolFmt("On", "Off"));
}
-
+
private FormatUtil() {}
private PredefDateFmt(TemporalConfig.Type type) {
_type = type;
}
-
+
@Override
public Value format(EvalContext ctx, Value expr, String fmtStr,
int firstDay, int firstWeekType) {
_trueVal = ValueSupport.toValue(trueStr);
_falseVal = ValueSupport.toValue(falseStr);
}
-
+
@Override
public Value format(EvalContext ctx, Value expr, String fmtStr,
int firstDay, int firstWeekType) {
}
}
-
+
}
assertEval("-.123%", "=FormatPercent(-0.0012345,3,False)");
assertEval("$12,345.00", "=FormatCurrency(12345)");
- assertEval("($12.34)", "=FormatCurrency(-12.345,-1,True,True)");
+ assertEval("-$12.34", "=FormatCurrency(-12.345,-1,True,False)");
assertEval("$12", "=FormatCurrency(12.345,0,True,True)");
- assertEval("-$.123", "=FormatCurrency(-0.12345,3,False)");
+ assertEval("($.123)", "=FormatCurrency(-0.12345,3,False)");
assertEval("1/1/1973 1:37:25 PM", "=FormatDateTime(#1/1/1973 1:37:25 PM#)");
assertEval("1:37:25 PM", "=FormatDateTime(#1:37:25 PM#,0)");