diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2019-01-30 00:49:32 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2019-01-30 00:49:32 +0000 |
commit | 229464aff25cee0ff6941174fefd4e3416800f9f (patch) | |
tree | 65e89d30a1a41051fe6a749fa2f662f838229be1 /src/main/java/com/healthmarketscience/jackcess/impl/expr | |
parent | f3c8bb34a4aad19a5879d193dc54bfe862bd94b1 (diff) | |
download | jackcess-229464aff25cee0ff6941174fefd4e3416800f9f.tar.gz jackcess-229464aff25cee0ff6941174fefd4e3416800f9f.zip |
more tests, more bug fixes for custom formats
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jdk8@1270 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main/java/com/healthmarketscience/jackcess/impl/expr')
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/impl/expr/FormatUtil.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/FormatUtil.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/FormatUtil.java index 2258591..34d750a 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/FormatUtil.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/FormatUtil.java @@ -936,7 +936,6 @@ public class FormatUtil private static Fmt parseCustomTextFormat(ExprBuf buf, Args args) { Fmt fmt = null; - Fmt emptyFmt = null; List<BiConsumer<StringBuilder,CharSource>> subFmts = new ArrayList<>(); int numPlaceholders = 0; @@ -1037,11 +1036,12 @@ public class FormatUtil flushPendingTextLiteral(pendingLiteral, subFmts); + Fmt emptyFmt = null; if(fmt == null) { fmt = new CharSourceFmt(subFmts, numPlaceholders, rightAligned, textCase); emptyFmt = NULL_FMT; - } else if(emptyFmt == null) { + } else { emptyFmt = (hasFmtChars ? new CharSourceFmt(subFmts, numPlaceholders, rightAligned, textCase) : @@ -1438,10 +1438,18 @@ public class FormatUtil private Value formatMaybeZero(BigDecimal bd, NumberFormat fmt) { // in theory we want to use the given format. however, if, due to // rounding, we end up with a number equivalent to zero, then we fall - // back to the zero format - int maxDecDigits = fmt.getMaximumFractionDigits(); - if(maxDecDigits < bd.scale()) { - bd = bd.setScale(maxDecDigits, NumberFormatter.ROUND_MODE); + // back to the zero format. if we are using scientific notation, + // however, then don't worry about this + if(!(fmt instanceof NumberFormatter.ScientificFormat)) { + int maxDecDigits = fmt.getMaximumFractionDigits(); + int mult = ((DecimalFormat)fmt).getMultiplier(); + while(mult > 1) { + ++maxDecDigits; + mult /= 10; + } + if(maxDecDigits < bd.scale()) { + bd = bd.setScale(maxDecDigits, NumberFormatter.ROUND_MODE); + } } if(BigDecimal.ZERO.compareTo(bd) == 0) { // fall back to zero format |