List of usage examples for java.math RoundingMode valueOf
public static RoundingMode valueOf(int rm)
From source file:py.una.pol.karaku.math.MathContextProvider.java
@PostConstruct void post() {//w w w. j a v a2 s .c o m scale = Integer.valueOf(pu.get(KARAKU_MATH_ROUNDING_SCALE, "4")); precision = Integer.valueOf(pu.get(KARAKU_MATH_ROUNDING_PRECISION, "0")); rm = RoundingMode.valueOf(pu.get(KARAKU_MATH_ROUNDING_MODE, RoundingMode.HALF_UP.toString())); log.info("Math Context initialized with a scale of {} and a round mode: {}", scale, rm); }
From source file:com.ancientprogramming.fixedformat4j.format.impl.FixedFormatManagerImpl.java
private FixedFormatDecimalData getFixedFormatDecimalData(FixedFormatDecimal annotation) { FixedFormatDecimalData result;/*from w w w.j a v a 2 s. co m*/ if (annotation != null) { result = new FixedFormatDecimalData(annotation.decimals(), annotation.useDecimalDelimiter(), annotation.decimalDelimiter(), RoundingMode.valueOf(annotation.roundingMode())); } else { result = FixedFormatDecimalData.DEFAULT; } return result; }
From source file:org.mifos.accounts.loan.business.LoanCalculationIntegrationTest.java
private void parseConfigParams(String paramType, String line, InternalConfiguration config) { String tempLine = line.substring(paramType.length(), line.length() - 1); String[] tokens = tempLine.split(","); for (String token2 : tokens) { String token = token2;//from w w w .j a v a 2s. co m if (StringUtils.isNotBlank(token)) { if (paramType.indexOf(initialRoundingMode) >= 0) { RoundingMode mode = RoundingMode.valueOf(token.toUpperCase()); config.setInitialRoundingMode(mode); token = getToken(tempLine, feeFrequency); if (token.toUpperCase().equals("PERIODIC")) { config.setFeeFrequency(FeeFrequencyType.PERIODIC); } else if (token.toUpperCase().equals("ONETIME")) { config.setFeeFrequency(FeeFrequencyType.ONETIME); } else { config.setFeeFrequency(null); } } else if (paramType.indexOf(initialRoundOffMultiple) >= 0) { config.setInitialRoundOffMultiple(token); token = getToken(tempLine, feeType); config.setIsFeeRateBased(true); if (token.equals(feeTypePrincipalPlusInterest)) { config.setFeeType(FeeFormula.AMOUNT_AND_INTEREST); } else if (token.equals(feeTypeInterest)) { config.setFeeType(FeeFormula.INTEREST); } else if (token.equals(feeTypePrincipal)) { config.setFeeType(FeeFormula.AMOUNT); } else if (token.equals(feeTypeValue)) { // don't use FeeFormula config.setIsFeeRateBased(false); } else { throw new RuntimeException("Unrecognized fee type: " + token); } } else if (paramType.indexOf(finalRoundingMode) >= 0) { RoundingMode mode = RoundingMode.valueOf(token.toUpperCase()); config.setFinalRoundingMode(mode); token = getToken(tempLine, feeValue); config.setFeeValue(token); } else if (paramType.indexOf(finalRoundOffMultiple) >= 0) { config.setFinalRoundOffMultiple(token); token = getToken(tempLine, feePercentage); int pos = token.indexOf("%"); token = token.substring(0, pos); config.setFeePercentage(token); } else if (paramType.indexOf(currencyRounding) >= 0) { RoundingMode mode = RoundingMode.valueOf(token.toUpperCase()); config.setCurrencyRoundingMode(mode); token = getToken(tempLine, gracePeriodType); GraceType type = null; if (token.toUpperCase().equals("ALL")) { type = GraceType.GRACEONALLREPAYMENTS; } else if (token.toUpperCase().equals("PRINCIPAL")) { type = GraceType.PRINCIPALONLYGRACE; } else { type = GraceType.NONE; } config.setGracePeriodType(type); } else if (paramType.indexOf(digitsAfterDecimal) >= 0) { config.setDigitsAfterDecimal(Short.parseShort(token)); token = getToken(tempLine, gracePeriod); config.setGracePeriod(Short.parseShort(token)); } else if (paramType.indexOf(daysInYear) >= 0) { config.setDaysInYear(Short.parseShort(token)); } /* * else if (paramType.indexOf(gracePeriodType)>= 0) { GraceType type = null; if * (token.toUpperCase().equals("ALL")) type = GraceType.GRACEONALLREPAYMENTS; else if * (token.toUpperCase().equals("PRINCIPAL")) type = GraceType.PRINCIPALONLYGRACE; else type = * GraceType.NONE; * * config.setGracePeriodType(type); } else if (paramType.indexOf(gracePeriod)>= 0) { if * (config.getGracePeriodType() != GraceType.NONE) config.setGracePeriod(Short.parseShort(token)); } */ break; } } }
From source file:org.openhab.binding.weather.internal.bus.BindingConfigParser.java
/** * Parses the bindingConfig of an item and returns a WeatherBindingConfig. *//* w w w . ja v a 2 s . co m*/ public WeatherBindingConfig parse(Item item, String bindingConfig) throws BindingConfigParseException { bindingConfig = StringUtils.trimToEmpty(bindingConfig); bindingConfig = StringUtils.removeStart(bindingConfig, "{"); bindingConfig = StringUtils.removeEnd(bindingConfig, "}"); String[] entries = bindingConfig.split("[,]"); WeatherBindingConfigHelper helper = new WeatherBindingConfigHelper(); for (String entry : entries) { String[] entryParts = StringUtils.trimToEmpty(entry).split("[=]"); if (entryParts.length != 2) { throw new BindingConfigParseException("A bindingConfig must have a key and a value"); } String key = StringUtils.trim(entryParts[0]); String value = StringUtils.trim(entryParts[1]); value = StringUtils.removeStart(value, "\""); value = StringUtils.removeEnd(value, "\""); try { helper.getClass().getDeclaredField(key).set(helper, value); } catch (Exception e) { throw new BindingConfigParseException("Could not set value " + value + " for attribute " + key); } } if (!helper.isValid()) { throw new BindingConfigParseException("Invalid binding: " + bindingConfig); } helper.type = StringUtils.replace(helper.type, "athmosphere", "atmosphere"); WeatherBindingConfig weatherConfig = null; if (helper.isForecast()) { Integer forecast = parseInteger(helper.forecast, bindingConfig); if (forecast < 0) { throw new BindingConfigParseException("Invalid binding, forecast must be >= 0: " + bindingConfig); } weatherConfig = new ForecastBindingConfig(helper.locationId, forecast, helper.type, helper.property); } else { weatherConfig = new WeatherBindingConfig(helper.locationId, helper.type, helper.property); } Weather validationInstance = new Weather(null); String property = weatherConfig.getWeatherProperty(); if (!Weather.isVirtualProperty(property) && !PropertyUtils.hasProperty(validationInstance, property)) { throw new BindingConfigParseException("Invalid binding, unknown type or property: " + bindingConfig); } boolean isDecimalTypeItem = item.getAcceptedDataTypes().contains(DecimalType.class); if (isDecimalTypeItem || Weather.isVirtualProperty(property)) { RoundingMode roundingMode = RoundingMode.HALF_UP; if (helper.roundingMode != null) { try { roundingMode = RoundingMode.valueOf(StringUtils.upperCase(helper.roundingMode)); } catch (IllegalArgumentException ex) { throw new BindingConfigParseException( "Invalid binding, unknown roundingMode: " + bindingConfig); } } Integer scale = 2; if (helper.scale != null) { scale = parseInteger(helper.scale, bindingConfig); if (scale < 0) { throw new BindingConfigParseException("Invalid binding, scale must be >= 0: " + bindingConfig); } } weatherConfig.setScale(roundingMode, scale); } weatherConfig.setUnit(Unit.parse(helper.unit)); if (StringUtils.isNotBlank(helper.unit) && weatherConfig.getUnit() == null) { throw new BindingConfigParseException("Invalid binding, unknown unit: " + bindingConfig); } try { if (!Weather.isVirtualProperty(property) && weatherConfig.hasUnit()) { String doubleTypeName = Double.class.getName(); String propertyTypeName = PropertyUtils.getPropertyTypeName(validationInstance, property); if (!StringUtils.equals(doubleTypeName, propertyTypeName)) { throw new BindingConfigParseException( "Invalid binding, unit specified but property is not a double type: " + bindingConfig); } } } catch (IllegalAccessException ex) { logger.error(ex.getMessage(), ex); throw new BindingConfigParseException(ex.getMessage()); } return weatherConfig; }
From source file:org.voltdb.regressionsuites.RegressionSuite.java
static protected void validateTableColumnOfScalarDecimal(VoltTable vt, int col, BigDecimal[] expected) { assertNotNull(expected);//from w w w .java2 s .com assertEquals(expected.length, vt.getRowCount()); int len = expected.length; for (int i = 0; i < len; i++) { assertTrue(vt.advanceRow()); BigDecimal actual = vt.getDecimalAsBigDecimal(col); if (expected[i] == null) { assertTrue(vt.wasNull()); assertEquals(null, actual); } else { BigDecimal rounded = expected[i].setScale(m_defaultScale, RoundingMode.valueOf(m_defaultRoundingMode)); assertEquals(rounded, actual); } } }