slash.common.io.Transfer.roundFraction()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中slash.common.io.Transfer.roundFraction()方法的一些代码示例,展示了Transfer.roundFraction()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transfer.roundFraction()方法的具体详情如下:
包路径:slash.common.io.Transfer
类名称:Transfer
方法名:roundFraction

Transfer.roundFraction介绍

暂无

代码示例

代码示例来源:origin: cpesch/RouteConverter

private static ValueAndOrientation position2nmea(Double degrees, Orientation aboveZero, Orientation belowZero) {
  if(degrees == null)
    return null;
  int asInt = (int) degrees.doubleValue();
  double behindDot = degrees - asInt;
  double behindDdMm = behindDot * SECONDS_OF_A_MINUTE;
  double ddmm = asInt * 100.0 + behindDdMm;
  double longitude = abs(ddmm);
  longitude = roundFraction(longitude, 10);
  Orientation eastOrWest = ddmm >= 0.0 ? aboveZero : belowZero;
  return new ValueAndOrientation(longitude, eastOrWest);
}

代码示例来源:origin: cpesch/RouteConverter

public static BigDecimal formatBigDecimal(Double aDouble, int maximumFractionCount) {
  if (aDouble == null)
    return null;
  if (isReduceDecimalPlaceToReasonablePrecision())
    aDouble = roundFraction(aDouble, maximumFractionCount);
  return BigDecimal.valueOf(aDouble);
}

代码示例来源:origin: cpesch/RouteConverter

public static Double formatDouble(Double aDouble, int maximumFractionCount) {
  if (aDouble == null)
    return null;
  if (isReduceDecimalPlaceToReasonablePrecision())
    aDouble = roundFraction(aDouble, maximumFractionCount);
  return aDouble;
}

代码示例来源:origin: cpesch/RouteConverter

private static String formatDoubleAsString(Double aDouble, int maximumFractionCount) {
  if (aDouble != null && isReduceDecimalPlaceToReasonablePrecision())
    aDouble = roundFraction(aDouble, maximumFractionCount);
  return Transfer.formatDoubleAsString(aDouble);
}

代码示例来源:origin: cpesch/RouteConverter

public static String formatElevation(Double elevation) {
  if (elevation == null)
    return "";
  UnitSystem unitSystem = RouteConverter.getInstance().getUnitSystemModel().getUnitSystem();
  double elevationInUnit = unitSystem.valueToUnit(elevation);
  if (abs(elevationInUnit) < 10.0)
    return format("%s %s", roundFraction(elevationInUnit, 1), unitSystem.getElevationName());
  else
    return format("%d %s", round(elevationInUnit), unitSystem.getElevationName());
}

代码示例来源:origin: cpesch/RouteConverter

public static String formatSpeed(Double speed) {
  if (speed == null)
    return "";
  UnitSystem unitSystem = RouteConverter.getInstance().getUnitSystemModel().getUnitSystem();
  double speedInUnit = unitSystem.distanceToUnit(speed) * METERS_OF_A_KILOMETER;
  if (abs(speedInUnit) < 10.0)
     return format("%s %s", roundFraction(speedInUnit, 1), unitSystem.getSpeedName());
  else
    return format("%d %s", round(speedInUnit), unitSystem.getSpeedName());
}

代码示例来源:origin: cpesch/RouteConverter

public static String formatDistance(Double distance) {
  // don't use isEmpty(distance) here since a 0.0 makes sense to display
  if (distance == null || distance <= 0.0)
    return "";
  UnitSystem unitSystem = RouteConverter.getInstance().getUnitSystemModel().getUnitSystem();
  double shortDistanceInUnit = unitSystem.shortDistanceToUnit(distance);
  if (abs(shortDistanceInUnit) < maximumDistanceDisplayedInSmallUnit)
    return format("%d %s", round(shortDistanceInUnit), unitSystem.getShortDistanceName());
  double distanceInUnit = unitSystem.distanceToUnit(distance);
  if (abs(distanceInUnit) < maximumDistanceDisplayedWithFraction)
    return format("%s %s", roundFraction(distanceInUnit, 1), unitSystem.getDistanceName());
  return format("%d %s", round(distanceInUnit), unitSystem.getDistanceName());
}

代码示例来源:origin: cpesch/RouteConverter

@Test
public void testRoundFraction() {
  assertDoubleEquals(1.0, roundFraction(1.1, 0));
  assertDoubleEquals(1.1, roundFraction(1.1, 1));
  assertDoubleEquals(11.0, roundFraction(11.1, 0));
  assertDoubleEquals(11.1, roundFraction(11.1, 1));
  assertDoubleEquals(1.004, roundFraction(1.004, 3));
  assertDoubleEquals(1.004, roundFraction(1.0044, 3));
  assertDoubleEquals(1.005, roundFraction(1.0045, 3));
  assertDoubleEquals(1.005, roundFraction(1.005, 3));
}

代码示例来源:origin: cpesch/RouteConverter

public static Double nmea2degrees(ValueAndOrientation nmea) {
  if(nmea == null)
    return null;
  double decimal = nmea.getValue() / 100.0;
  int asInt = (int) decimal;
  double behindDot = ((decimal - asInt) * 100.0) / SECONDS_OF_A_MINUTE;
  double degrees = asInt + behindDot;
  degrees = roundFraction(degrees, 10);
  Orientation orientation = nmea.getOrientation();
  boolean southOrWest = orientation.equals(South) || orientation.equals(West);
  return southOrWest ? -degrees : degrees;
}

相关文章