Changeset 4541 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r4476 r4541 12 12 import static java.lang.Math.toRadians; 13 13 14 import java.math.BigDecimal; 15 import java.math.MathContext; 14 16 import java.text.DecimalFormat; 15 17 import java.text.NumberFormat; … … 28 30 public class LatLon extends Coordinate { 29 31 32 30 33 /** 31 34 * Minimum difference in location to not be represented as the same position. … … 33 36 */ 34 37 public static final double MAX_SERVER_PRECISION = 1e-7; 38 public static final int MAX_SERVER_DIGITS = 7; 35 39 36 40 private static DecimalFormat cDmsMinuteFormatter = new DecimalFormat("00"); … … 240 244 */ 241 245 public static double roundToOsmPrecision(double value) { 242 return Math.round(value / MAX_SERVER_PRECISION) * MAX_SERVER_PRECISION; 246 double absV = Math.abs(value); 247 int numOfDigits = MAX_SERVER_DIGITS + (absV < 1 ? 0 : (absV < 10 ? 1 : (absV < 100 ? 2 : 3))); 248 return BigDecimal.valueOf(value).round(new MathContext(numOfDigits)).doubleValue(); 249 //return Math.round(value / MAX_SERVER_PRECISION) * MAX_SERVER_PRECISION; // Old method, causes rounding errors (see LatLonTest) ! 243 250 } 244 251
Note:
See TracChangeset
for help on using the changeset viewer.