code: @VisibleForTesting
      protected static double getNearestNiceValue(
              final double value, final DistanceUnit scaleUnit, final boolean lockUnits) {
          DistanceUnit bestUnit = bestUnit(scaleUnit, value, lockUnits);
          double factor = scaleUnit.convertTo(1.0, bestUnit);
  
          // nearest power of 10 lower than value
          int digits = (int) Math.floor((Math.log(value * factor) / Math.log(10)));
          double pow10 = Math.pow(10, digits);
  
          // ok, find first character
          double firstChar = value * factor / pow10;
  
          // right, put it into the correct bracket
          int barLen;
          if (firstChar >= 10.0) {
              barLen = 10;
          } else if (firstChar >= 5.0) {
              barLen = 5;
          } else if (firstChar >= 2.0) {
              barLen = 2;
          } else {
              barLen = 1;
          }
  
          // scale it up the correct power of 10
          return barLen * pow10 / factor;
      }
docs: Reduce the given value to the nearest smaller 1 significant digit number starting with 1, 2 or 5.
  
  @param value the value to find a nice number for.
  @param scaleUnit the unit of the value.
  @param lockUnits if set, the values are not scaled to a "nicer" unit.