code: public static double getRounded (final double dValue,
                                     @Nonnegative final int nScale,
                                     @Nonnull final RoundingMode eMode,
                                     @Nonnull final EDecimalType eType)
    {
      ValueEnforcer.isGE0 (nScale, "Scale");
      ValueEnforcer.notNull (eMode, "RoundingMode");
      ValueEnforcer.notNull (eType, "Type");
  
      if (Double.isNaN (dValue) || Double.isInfinite (dValue))
        return dValue;
  
      final BigDecimal bd = BigDecimal.valueOf (dValue);
      double ret;
      if (eType.isExponential ())
      {
        final BigDecimal bc = new BigDecimal (bd.unscaledValue (), bd.precision () - 1);
        ret = bc.setScale (nScale, eMode).scaleByPowerOfTen (bc.scale () - bd.scale ()).doubleValue ();
      }
      else
        ret = bd.setScale (nScale, eMode).doubleValue ();
  
      return ret;
    }
docs: Source: http://www.luschny.de/java/doubleformat.html
  
  @param dValue
  The value to be rounded
  @param nScale
  The precision of the decimal scale. If type is
  {@link EDecimalType#FIX} the decimal scale, else the (carrying scale
  - 1). Should be &ge; 0.
  @param eType
  The formatting type. May not be <code>null</code>.
  @param eMode
  The rounding mode to be used. May not be <code>null</code>.
  @return the rounded value according to the specified rules. For NaN and
  infinite values, the input value is returned as is.