This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new c565768 Avoid formatting zero as "0.0E0".
c565768 is described below
commit c5657680d26e0ccae850752788304e78446a22eb
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Thu Sep 20 12:12:27 2018 +0200
Avoid formatting zero as "0.0E0".
---
.../sis/util/collection/TreeTableFormat.java | 43 ++++++++++++----------
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git
a/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
b/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
index 154c201..a0328be 100644
---
a/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
+++
b/core/sis-utility/src/main/java/org/apache/sis/util/collection/TreeTableFormat.java
@@ -794,26 +794,31 @@ public class TreeTableFormat extends
TabularFormat<TreeTable> {
*/
final Format format = getFormat(value.getClass());
if (format instanceof DecimalFormat &&
Numbers.isFloat(value.getClass())) {
- /*
- * The default floating point formats use only 3 fraction
digits. We adjust that to the number
- * of digits required by the number to format. We do that
only if no NumberFormat was inferred
- * for the whole column (in order to keep column format
uniform). We use enough precision for
- * all fraction digits except the last 2, in order to let
DecimalFormat round the number.
- */
- if (adaptableFormat == null) {
- adaptableFormat = (DecimalFormat) format.clone();
- defaultPattern = adaptableFormat.toPattern();
- }
- final int nf =
DecimalFunctions.fractionDigitsForValue(((Number) value).doubleValue());
- final boolean preferScientificNotation = (nf > 20 || nf <
7); // == (value < 1E-4 || value > 1E+9)
- if (preferScientificNotation != usingScientificNotation) {
- usingScientificNotation = preferScientificNotation;
- adaptableFormat.applyPattern(preferScientificNotation
? "0.0############E0" : defaultPattern);
- }
- if (!preferScientificNotation) {
- adaptableFormat.setMaximumFractionDigits(nf - 2);
// All significand fraction digits except last two.
+ final double number = ((Number) value).doubleValue();
+ if (number != (int) number) { // Cast to 'int' instead
of 'long' as a way to limit to about 2E9.
+ /*
+ * The default floating point format uses only 3
fraction digits. We adjust that to the number
+ * of digits required by the number to format. We do
that only if no NumberFormat was inferred
+ * for the whole column (in order to keep column
format uniform). We use enough precision for
+ * all fraction digits except the last 2, in order to
let DecimalFormat round the number.
+ */
+ if (adaptableFormat == null) {
+ adaptableFormat = (DecimalFormat) format.clone();
+ defaultPattern = adaptableFormat.toPattern();
+ }
+ final int nf =
DecimalFunctions.fractionDigitsForValue(number);
+ final boolean preferScientificNotation = (nf > 20 ||
nf < 7); // == (value < 1E-4 || value > 1E+9)
+ if (preferScientificNotation !=
usingScientificNotation) {
+ usingScientificNotation = preferScientificNotation;
+
adaptableFormat.applyPattern(preferScientificNotation ? "0.0############E0" :
defaultPattern);
+ }
+ if (!preferScientificNotation) {
+ adaptableFormat.setMaximumFractionDigits(nf - 2);
// All significand fraction digits except last two.
+ }
+ text = adaptableFormat.format(value);
+ } else {
+ text = format.format(value);
}
- text = adaptableFormat.format(value);
} else {
text = (format != null) ? format.format(value) :
value.toString();
}