aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/healthmarketscience/jackcess/impl/expr
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2019-01-30 00:49:32 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2019-01-30 00:49:32 +0000
commit229464aff25cee0ff6941174fefd4e3416800f9f (patch)
tree65e89d30a1a41051fe6a749fa2f662f838229be1 /src/main/java/com/healthmarketscience/jackcess/impl/expr
parentf3c8bb34a4aad19a5879d193dc54bfe862bd94b1 (diff)
downloadjackcess-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.java20
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