Rounds a number to the first two non-zero decimal places.
    Adapted from https://stackoverflow.com/a/38838513/2765666.
    
    :param decimal: The decimal number to round.
    :return: A new decimal representing the rounded value.
509536
def round_two_non_zero_dp(decimal):
    
    log10 = decimal.log10().to_integral_exact(rounding=ROUND_FLOOR) \
        if decimal else 0
    div = Decimal(10) ** (Decimal(1) - log10) if log10 < 0 else Decimal(100)
    return (decimal * div).to_integral_exact(rounding=ROUND_HALF_UP) / div
664938
function preciseRound(num) {
        var decimals = options.round ? 0 : 1;
        return Math.round(num * Math.pow(10, decimals)) / Math.pow(10, decimals);
      }
454229
def float_to_decimal(f):
    
    n, d = f.as_integer_ratio()
    numerator, denominator = Decimal(n), Decimal(d)
    ctx = Context(prec=60)
    result = ctx.divide(numerator, denominator)
    while ctx.flags[Inexact]:
        ctx.flags[Inexact] = False
        ctx.prec *= 2
        result = ctx.divide(numerator, denominator)
    return result
53022
public static double round(double toBeRounded, int digits) {
		if (digits < 0) {
			QuickUtils.log.e("must be greater than 0");
			return 0;
		}
		String formater = "";
		for (int i = 0; i < digits; i++) {
			formater += "#";
		}

		DecimalFormat twoDForm = new DecimalFormat("#." + formater, new DecimalFormatSymbols(Locale.US));
		return Double.valueOf(twoDForm.format(toBeRounded));
	}
121957
def round(self, value_array):
        

        rounded_values = np.zeros(value_array.shape)
        rounded_values[np.argmax(value_array)] = 1
        return rounded_values
690007
def roundClosestValid(val, res, decimals=None):
        
        if decimals is None and "." in str(res):
            decimals = len(str(res).split('.')[1])

        return round(round(val / res) * res, decimals)
40814
public static double round(double x, int decimal) {
        if (decimal < 0) {
            return round(x / pow(10, -decimal)) * pow(10, -decimal);
        } else {
            return round(x * pow(10, decimal)) / pow(10, decimal);
        }
    }
904344
private Format decimalFormat(int fractionPrecision) {
		DecimalFormat format;
		if (fractionPrecision == 0) {
			format = new DecimalFormat("###0");
		} else if (fractionPrecision > 0) {
			StringBuilder formatSb = new StringBuilder();
			formatSb.append("###0.");
			appendChars(formatSb, ZERO_CHARS, fractionPrecision);
			format = new DecimalFormat(formatSb.toString());
		} else {
			format = new DecimalFormat("###0.###");
		}
		return format;
	}
558798
def format_value(value):
    
    value = decimal.Decimal(str(value))
    if int(value) == value:
        return int(value)

    # On Python 3, an explicit cast to float is required
    return float(round(value, 1))
33322
private static DecimalFormat createFormatter(int precision) {
        if (precision < 0)
            throw new IllegalArgumentException("Precision must be non-negative");

        if (precision == 0)
            return new DecimalFormat("0", symbols);

        StringBuilder sb = new StringBuilder("0.");
        for (int i = 0; i < precision; i++) {
            sb.append("0");
        }
        return new DecimalFormat(sb.toString(), symbols);
    }
537345
def round_to_n_decimal_places(array, n=3):
    
    # check if in scientific notation
    if issubclass(array.__class__, float) and '%.e'%array == str(array):
        return array # do nothing

    shape = np.shape(array)
    out = ((np.atleast_1d(array) * 10**n).round().astype('int') / (10.**n))
    return out.reshape(shape)
571722
def drop_trailing_zeros_decimal(num):
    
    out = str(num)
    return out.rstrip('0').rstrip('.') if '.' in out else out
275466
function round(value, digits)
{
    if (! digits) { digits = 0; }
    var scale = Math.pow(10, digits);
    return Math.round(value * scale) / scale;
}
235256
def fix_coordinate_decimal(d):
    
    try:
        for idx, n in enumerate(d["geo"]["geometry"]["coordinates"]):
            d["geo"]["geometry"]["coordinates"][idx] = round(n, 5)
    except Exception as e:
        logger_misc.error("fix_coordinate_decimal: {}".format(e))
    return d
430339
public static final double round(double value, double precision)
   {
      precision = Math.pow(10, precision);
      return Math.round(value * precision) / precision;
   }
117541
public static double roundWithDecimalPlace(double doubleNumber,
            int decimalPlace) {
        double pow = pow(10, decimalPlace);
        return Math.round(doubleNumber * pow) / pow;
    }
412875
function Decimal(value) {
      var x = this;

      // Decimal called without new.
      if (!(x instanceof Decimal)) return new Decimal(value);

      // Retain a reference to this Decimal constructor, and shadow Decimal.prototype.constructor
      // which points to Object.
      x.constructor = Decimal;

      // Duplicate.
      if (value instanceof Decimal) {
        x.s = value.s;
        x.e = value.e;
        x.d = (value = value.d) ? value.slice() : value;
        return;
      }

      if (typeof value === 'number') {

        // Reject Infinity/NaN.
        if (value * 0 !== 0) {
          throw Error(invalidArgument + value);
        }

        if (value > 0) {
          x.s = 1;
        } else if (value < 0) {
          value = -value;
          x.s = -1;
        } else {
          x.s = 0;
          x.e = 0;
          x.d = [0];
          return;
        }

        // Fast path for small integers.
        if (value === ~~value && value < 1e7) {
          x.e = 0;
          x.d = [value];
          return;
        }

        return parseDecimal(x, value.toString());
      } else if (typeof value !== 'string') {
        throw Error(invalidArgument + value);
      }

      // Minus sign?
      if (value.charCodeAt(0) === 45) {
        value = value.slice(1);
        x.s = -1;
      } else {
        x.s = 1;
      }

      if (isDecimal.test(value)) parseDecimal(x, value);
      else throw Error(invalidArgument + value);
    }