Returns the closest {@code decimal} to the argument, with given scale,
using HALF_UP mode

Any numeric string recognized by {@code BigDecimal} is supported.

@param value A valid number string

@return the rounded number.

@see BigDecimal
432248
public static String round(String value, int scale) {
        BigDecimal bd;
        try {
            bd = new BigDecimal(value);
            bd = bd.setScale(scale, RoundingMode.HALF_UP);
            return bd.toString();
        } catch (Exception e) {
            return null;
        }
    }
478238
public static BigDecimal roundHalfEven(BigDecimal value, int scale) {
		return round(value, scale, RoundingMode.HALF_EVEN);
	}
245726
public static double getDouble(
    Object      value)
  {
    if (value == null)
    {
        return 0;
    }

    return Double.valueOf(value.toString()).doubleValue();

  }
427788
public static final Integer getInteger(Number value)
   {
      Integer result = null;
      if (value != null)
      {
         if (value instanceof Integer)
         {
            result = (Integer) value;
         }
         else
         {
            result = Integer.valueOf((int) Math.round(value.doubleValue()));
         }
      }
      return (result);
   }
202768
public static Decimal sround(Decimal b0, int r) {
		if (r >= b0.scale) {
			return b0;
		}

		BigDecimal b2 = b0.toBigDecimal().movePointRight(r)
				.setScale(0, RoundingMode.HALF_UP)
				.movePointLeft(r);
		int p = b0.precision;
		int s = b0.scale;
		if (r < 0) {
			return fromBigDecimal(b2, Math.min(38, 1 + p - s), 0);
		} else {  // 0 <= r < s
			return fromBigDecimal(b2, 1 + p - s + r, r);
		}
	}
1316864
public static BigDecimal round(String numberStr, int scale, RoundingMode roundingMode) {
		Assert.notBlank(numberStr);
		if (scale < 0) {
			scale = 0;
		}
		return round(toBigDecimal(numberStr), scale, roundingMode);
	}
267470
private Double scale(Double value, Double min, Double max) {
        if(min.equals(max)) {
            if(value>max) {
                return 1.0;
            }
            else if(value==max && value!=0.0) {
                return 1.0;
            }
            else {
                return 0.0;
            }
        }
        else {
            return (value-min)/(max-min);
        }
    }
688740
public static Decimal fromBigDecimal(BigDecimal bd, int precision, int scale) {
		bd = bd.setScale(scale, RoundingMode.HALF_UP);
		if (bd.precision() > precision) {
			return null;
		}

		long longVal = -1;
		if (precision <= MAX_COMPACT_PRECISION) {
			longVal = bd.movePointRight(scale).longValueExact();
		}
		return new Decimal(precision, scale, longVal, bd);
	}
477942
public static String fixed(EvaluationContext ctx, Object number, @IntegerDefault(2) Object decimals, @BooleanDefault(false) Object noCommas) {
        BigDecimal _number = Conversions.toDecimal(number, ctx);
        _number = _number.setScale(Conversions.toInteger(decimals, ctx), RoundingMode.HALF_UP);

        DecimalFormat format = new DecimalFormat();
        format.setMaximumFractionDigits(9);
        format.setGroupingUsed(!Conversions.toBoolean(noCommas, ctx));
        return format.format(_number);
    }
248470
public static final BigDecimal printUnits(Number value)
   {
      return (value == null ? BIGDECIMAL_ONE : new BigDecimal(value.doubleValue() / 100));
   }
756527
public static double roundHalfUp(double d, int scale) {
		return BigDecimal.valueOf(d).setScale(scale, RoundingMode.HALF_UP).doubleValue();
	}
608591
@SuppressWarnings("unchecked")
    private T roundOffValueToStep(T value) {
        double d = Math.round(value.doubleValue() / absoluteStepValuePrim) * absoluteStepValuePrim;
        return (T) numberType.toNumber(Math.max(absoluteMinValuePrim, Math.min(absoluteMaxValuePrim, d)));
    }
261747
public static long round(SoyValue value) {
    if (value instanceof IntegerData) {
      return value.longValue();
    } else {
      return Math.round(value.numberValue());
    }
  }
390732
public static BigDecimal roundup(EvaluationContext ctx, Object number, Object numDigits) {
        BigDecimal _number = Conversions.toDecimal(number, ctx);
        int _numDigits = Conversions.toInteger(numDigits, ctx);

        return ExpressionUtils.decimalRound(_number, _numDigits, RoundingMode.UP);
    }
816737
public static BigDecimal round(EvaluationContext ctx, Object number, Object numDigits) {
        BigDecimal _number = Conversions.toDecimal(number, ctx);
        int _numDigits = Conversions.toInteger(numDigits, ctx);

        return ExpressionUtils.decimalRound(_number, _numDigits, RoundingMode.HALF_UP);
    }
959131
public static BigDecimal rounddown(EvaluationContext ctx, Object number, Object numDigits) {
        BigDecimal _number = Conversions.toDecimal(number, ctx);
        int _numDigits = Conversions.toInteger(numDigits, ctx);

        return ExpressionUtils.decimalRound(_number, _numDigits, RoundingMode.DOWN);
    }
586454
public static final Double parsePercent(String value)
   {
      return value == null ? null : Double.valueOf(Double.parseDouble(value) * 100.0);
   }