code: public static double scaleValue(double value, int decimals) {
      BigDecimal bd = BigDecimal.valueOf(value);
      return bd.setScale(decimals, RoundingMode.HALF_UP).doubleValue();
    }
docs: Scales a double value with decimals