summaryrefslogtreecommitdiffstats
path: root/document/src/main
diff options
context:
space:
mode:
authorJo Kristian Bergum <bergum@yahoo-inc.com>2017-02-09 14:45:32 +0100
committerGitHub <noreply@github.com>2017-02-09 14:45:32 +0100
commit31ee64ebfc9f3268ca9ead26a24a19e8f9fff1f0 (patch)
treea6e3cdddd57b478784fc79fdd1c5cd58611241b6 /document/src/main
parentf7d13af1f8b6b880473f3ae832400e5bddd96257 (diff)
parentff12f27c37e3de29ff6dfd207948269573ae0d81 (diff)
Merge pull request #1731 from yahoo/arnej/format-degrees-nicely
avoid scientific notation in degrees formatting
Diffstat (limited to 'document/src/main')
-rw-r--r--document/src/main/java/com/yahoo/document/PositionDataType.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/document/src/main/java/com/yahoo/document/PositionDataType.java b/document/src/main/java/com/yahoo/document/PositionDataType.java
index a2a1c6012a1..816fcd7bdf7 100644
--- a/document/src/main/java/com/yahoo/document/PositionDataType.java
+++ b/document/src/main/java/com/yahoo/document/PositionDataType.java
@@ -7,6 +7,10 @@ import com.yahoo.document.datatypes.Struct;
import com.yahoo.geo.DegreesParser;
import com.yahoo.document.serialization.XmlStream;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.util.Locale;
+
/**
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
*/
@@ -20,6 +24,19 @@ public final class PositionDataType {
private static final Field FFIELD_X = INSTANCE.getField(FIELD_X);
private static final Field FFIELD_Y = INSTANCE.getField(FIELD_Y);
+ private static final DecimalFormat degreeFmt;
+
+ static {
+ degreeFmt = new DecimalFormat("0.0#####", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
+ degreeFmt.setMinimumIntegerDigits(1);
+ degreeFmt.setMinimumFractionDigits(1);
+ degreeFmt.setMaximumFractionDigits(6);
+ }
+
+ static String fmtD(double degrees) {
+ return degreeFmt.format(degrees);
+ }
+
private PositionDataType() {
// unreachable
}
@@ -29,10 +46,10 @@ public final class PositionDataType {
double ns = getYValue(pos).getInteger() / 1.0e6;
double ew = getXValue(pos).getInteger() / 1.0e6;
buf.append(ns < 0 ? "S" : "N");
- buf.append(ns < 0 ? (-ns) : ns);
+ buf.append(fmtD(ns < 0 ? (-ns) : ns));
buf.append(";");
buf.append(ew < 0 ? "W" : "E");
- buf.append(ew < 0 ? (-ew) : ew);
+ buf.append(fmtD(ew < 0 ? (-ew) : ew));
return buf.toString();
}