mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-22 21:55:39 +00:00
30 lines
1.0 KiB
Java
30 lines
1.0 KiB
Java
package com.sap.sse.common.util;
|
|
|
|
|
|
public class RoundingUtil {
|
|
public static final RoundingUtil distanceDecimalFormatter = new RoundingUtil(2);
|
|
public static final RoundingUtil knotsDecimalFormatter = new RoundingUtil(2);
|
|
public static final RoundingUtil bearingDecimalFormatter = new RoundingUtil(1);
|
|
public static final RoundingUtil speedDecimalFormatter = new RoundingUtil(1);
|
|
public static final RoundingUtil latLngDecimalFormatter = new RoundingUtil(7);
|
|
|
|
private final double shiftFactor;
|
|
|
|
private RoundingUtil(int decimals) {
|
|
shiftFactor = getShiftFactor(decimals);
|
|
}
|
|
|
|
private static double getShiftFactor(int decimals) {
|
|
return Math.pow(10, decimals);
|
|
}
|
|
|
|
public double format(double value) {
|
|
return ((double) Math.round(value * shiftFactor)) / shiftFactor;
|
|
}
|
|
|
|
public static double format(double value, int decimals) {
|
|
final double shiftFactor = getShiftFactor(decimals);
|
|
return ((double) Math.round(value * shiftFactor)) / shiftFactor;
|
|
}
|
|
}
|