[#1354] Export Lat & Long with 5 decimals
Idk, this is not per se a very dynamic solution (as in 'you only specify these 2 exceptions somewhere hidden deep inside a method'...) Ah well, it works for now.
This commit is contained in:
parent
72847b96eb
commit
7fada6f88c
@ -132,7 +132,13 @@ public class CSVExport {
|
||||
// Store CSV line
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
double value = fieldValues.get(i).get(pos);
|
||||
writer.print(TextUtil.doubleToString(units[i].toUnit(value)));
|
||||
// The latitude and longitude fields need a bit more accurate formatting
|
||||
if (fields[i] == FlightDataType.TYPE_LATITUDE || fields[i] == FlightDataType.TYPE_LONGITUDE) {
|
||||
writer.print(TextUtil.doubleToString(units[i].toUnit(value), 5));
|
||||
} else {
|
||||
writer.print(TextUtil.doubleToString(units[i].toUnit(value)));
|
||||
}
|
||||
|
||||
if (i < fields.length - 1) {
|
||||
writer.print(fieldSeparator);
|
||||
}
|
||||
|
@ -49,8 +49,7 @@ public class TextUtil {
|
||||
* @param d the value to present.
|
||||
* @return a representation with suitable precision.
|
||||
*/
|
||||
public static final String doubleToString(double d) {
|
||||
|
||||
public static final String doubleToString(double d, int decimalPlaces) {
|
||||
// Check for special cases
|
||||
if (MathUtil.equals(d, 0))
|
||||
return "0";
|
||||
@ -65,7 +64,6 @@ public class TextUtil {
|
||||
return "Inf";
|
||||
}
|
||||
|
||||
|
||||
final String sign = (d < 0) ? "-" : "";
|
||||
double abs = Math.abs(d);
|
||||
|
||||
@ -75,9 +73,13 @@ public class TextUtil {
|
||||
}
|
||||
|
||||
// Check whether decimal or exponential notation is shorter
|
||||
|
||||
String exp = exponentialFormat(abs);
|
||||
String dec = decimalFormat(abs);
|
||||
String dec;
|
||||
if (decimalPlaces < 0) {
|
||||
dec = decimalFormat(abs);
|
||||
} else {
|
||||
dec = decimalFormat(abs, decimalPlaces);
|
||||
}
|
||||
|
||||
if (dec.length() <= exp.length())
|
||||
return sign + dec;
|
||||
@ -85,6 +87,18 @@ public class TextUtil {
|
||||
return sign + exp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string of the double value with suitable precision for storage.
|
||||
* The string is the shortest representation of the value including at least
|
||||
* 5 digits of precision.
|
||||
*
|
||||
* @param d the value to present.
|
||||
* @return a representation with suitable precision.
|
||||
*/
|
||||
public static final String doubleToString(double d) {
|
||||
return doubleToString(d, -1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* value must be positive and not zero!
|
||||
@ -123,6 +137,16 @@ public class TextUtil {
|
||||
return shortDecimal(value, decimals);
|
||||
}
|
||||
|
||||
/*
|
||||
* value must be positive and not zero!
|
||||
*/
|
||||
private static String decimalFormat(double value, int decimals) {
|
||||
if (value >= 10000)
|
||||
return "" + (int) (value + 0.5);
|
||||
|
||||
return shortDecimal(value, decimals);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user