Example usage for java.math BigDecimal valueOf

List of usage examples for java.math BigDecimal valueOf

Introduction

In this page you can find the example usage for java.math BigDecimal valueOf.

Prototype

public static BigDecimal valueOf(double val) 

Source Link

Document

Translates a double into a BigDecimal , using the double 's canonical string representation provided by the Double#toString(double) method.

Usage

From source file:es.tid.fiware.rss.service.SettlementManager.java

/**
 * Create RS Model.//ww  w.j ava 2s .co  m
 * 
 * @param providerId
 * @param productClass
 * @param revenue
 * @throws IOException
 */
public void runCreateRSModel(String providerId, String productClass, Long revenue) throws IOException {
    logger.debug("Creating RsModel. Provider: {} productClass {}  revenue:", providerId, productClass,
            revenue.toString());
    SetRevenueShareConf rsModel = new SetRevenueShareConf();
    SetRevenueShareConfId id = new SetRevenueShareConfId();
    rsModel.setId(id);
    rsModel.setNuPercRevenueShare(BigDecimal.valueOf(revenue.longValue()));
    id.setTxAppProviderId(providerId);
    id.setProductClass(productClass);
    id.setNuObId(Long.valueOf(1));
    id.setCountryId(Long.valueOf(1));
    revenueShareConfDao.create(rsModel);
}

From source file:com.bosscs.spark.commons.utils.Utils.java

/**
 * Cast number type.//from  w  ww.  j  a  v a  2s .c  om
 *
 * @param object the object
 * @param clazz  the clazz
 * @return object
 */
public static Object castNumberType(Object object, Class clazz) {

    if (Number.class.isAssignableFrom(clazz)) {
        //            AtomicInteger, AtomicLong, BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, Short
        if (Double.class.isAssignableFrom(clazz)) {
            return ((Number) object).doubleValue();
        } else if (Long.class.isAssignableFrom(clazz)) {
            return ((Number) object).longValue();

        } else if (Float.class.isAssignableFrom(clazz)) {
            return ((Number) object).floatValue();

        } else if (Integer.class.isAssignableFrom(clazz)) {
            return ((Number) object).intValue();

        } else if (Short.class.isAssignableFrom(clazz)) {
            return ((Number) object).shortValue();

        } else if (Byte.class.isAssignableFrom(clazz)) {
            return ((Number) object).byteValue();

        } else if (BigInteger.class.isAssignableFrom(clazz)) {
            return BigInteger.valueOf(((Number) object).longValue());

        } else if (BigDecimal.class.isAssignableFrom(clazz)) {
            return BigDecimal.valueOf(((Number) object).longValue());

        } else if (AtomicLong.class.isAssignableFrom(clazz)) {
            return new AtomicLong(((Number) object).longValue());

        } else if (AtomicInteger.class.isAssignableFrom(clazz)) {
            return new AtomicInteger(((Number) object).intValue());
        }
    }
    throw new ClassCastException("it is not a Number Type" + object.getClass() + "|" + clazz);
}

From source file:fragment.web.TenantsControllerTest.java

private SpendAlertSubscription createSpendAlertSubscription(Tenant tenant) {
    SpendAlertSubscription spendAlert = new SpendAlertSubscription();
    spendAlert.setAccountHolder(tenant);
    spendAlert.setData("TEST");
    spendAlert.setUser(userService.getUserByParam("id", "4", false));
    spendAlert.setPercentage(BigDecimal.valueOf(100));
    spendAlert.setSubscriptionType(1);//  www  .j  a  v  a 2  s .  com
    spendAlertDAO.save(spendAlert);
    return spendAlert;
}

From source file:org.devgateway.ocds.web.rest.controller.CorruptionRiskDashboardIndicatorsStatsController.java

@ApiOperation(value = "Percent of total projects flagged (denominator is total projects)")
@RequestMapping(value = "/api/percentTotalProjectsFlaggedByYear", method = { RequestMethod.POST,
        RequestMethod.GET }, produces = "application/json")
public List<DBObject> percentTotalProjectsFlaggedByYear(final YearFilterPagingRequest filter) {

    //get the total projects flagged by year
    List<DBObject> totalFlaggedProjects = totalFlaggedProjectsByIndicatorTypeByYear(filter);

    //denominator total projects eligible by year
    List<DBObject> totalProjectsByYear = totalProjectsByYear(filter);

    totalFlaggedProjects.forEach(e -> {
        findByYearAndTypeAndMonth(totalProjectsByYear, (Integer) e.get(Keys.YEAR), null,
                (Integer) e.get(Keys.MONTH)).forEach(f -> {
                    e.put(Keys.PROJECT_COUNT, f.get(Keys.PROJECT_COUNT));
                    e.put(Keys.PERCENT,//from ww  w.j a v  a 2 s  .c om
                            (BigDecimal.valueOf((Integer) e.get(Keys.FLAGGED_PROJECT_COUNT))
                                    .setScale(BIGDECIMAL_SCALE)
                                    .divide(BigDecimal.valueOf((Integer) f.get(Keys.PROJECT_COUNT)),
                                            BigDecimal.ROUND_HALF_UP)
                                    .multiply(ONE_HUNDRED)));
                });
    });

    return totalFlaggedProjects;
}

From source file:io.coala.time.TimeSpan.java

/**
 * @param divisor the {@link Dimensionless} {@link Measure}
 * @return a new {@link TimeSpan}//from w  w w.  ja v  a 2 s  . c  o  m
 */
@SuppressWarnings("unchecked")
public TimeSpan divide(final Measurable<Dimensionless> divisor) {
    return divide(divisor instanceof DecimalMeasure
            ? MeasureUtil.toUnit((DecimalMeasure) divisor, Unit.ONE).getValue()
            : BigDecimal.valueOf(divisor.doubleValue(Unit.ONE)));
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.excelimport.EntityDataImporter.java

private Object readPropertyValue(Cell nonEmptyCell, PropertyExpression<?> nonReleasenameProperty) {
    if (nonReleasenameProperty instanceof EnumerationPropertyExpression) {
        return getEnumPropertyValue(nonEmptyCell, nonReleasenameProperty);
    } else if (nonReleasenameProperty.getType().equals(BuiltinPrimitiveType.INTEGER)) {
        Double doubleValue = getCellValueOfType(nonEmptyCell, Double.class);
        return doubleValue == null ? null : BigInteger.valueOf(doubleValue.longValue());
    } else if (nonReleasenameProperty.getType().equals(BuiltinPrimitiveType.DECIMAL)) {
        Double doubleValue = getCellValueOfType(nonEmptyCell, Double.class);
        return doubleValue == null ? null : BigDecimal.valueOf(doubleValue.doubleValue());
    } else if (nonReleasenameProperty.getType().equals(BuiltinPrimitiveType.DATE)) {
        return getCellValueOfType(nonEmptyCell, Date.class);
    } else if (nonReleasenameProperty.getType().equals(BuiltinPrimitiveType.BOOLEAN)) {
        String stringValue = getCellValueOfType(nonEmptyCell, String.class);
        return Boolean.valueOf(Boolean.parseBoolean(stringValue));
    } else if (nonReleasenameProperty.getType().equals(BuiltinPrimitiveType.STRING)) {
        return getStringPropertyValue(nonEmptyCell, nonReleasenameProperty);
    } else {//  w w w .jav  a  2  s.  com
        LOGGER.info("Property type for Java enum: {0}", nonReleasenameProperty.getClass().getName());
        return resolveJavaEnum(nonReleasenameProperty.getType().getName(),
                ExcelUtils.getCellValue(nonEmptyCell, false));
    }
}

From source file:com.jeans.iservlet.controller.impl.AssetsController.java

/**
 * ???Map??String???????null/*  www  . j  a va 2s  . co m*/
 * 
 * @return
 * @throws Exception
 */
private Map<String, Object> transProps(Map<String, String> props) throws Exception {
    Map<String, Object> p = new HashMap<String, Object>();
    Set<String> keys = props.keySet();
    for (String key : keys) {
        String value = props.get(key);
        if ("expiredTime".equals(key) || "purchaseTime".equals(key)) {
            p.put(key, "".equals(value) ? null : (new SimpleDateFormat("yyyy-MM-dd")).parse(value));
        } else if ("quantity".equals(key) || "number".equals(key)) {
            p.put(key, Integer.parseInt(value));
        } else if ("cost".equals(key)) {
            p.put(key, BigDecimal.valueOf(Double.parseDouble(value)));
        } else if ("warranty".equals(key) || "importance".equals(key) || "softwareType".equals(key)
                || "type".equals(key) || "catalog".equals(key) || "state".equals(key)) {
            p.put(key, Byte.parseByte(value));
        } else if ("ownerId".equals(key)) {
            p.put("owner", (Employee) hrService.loadUnitByType(Long.parseLong(value), HRUnit.EMPLOYEE));
        } else {
            p.put(key, value);
        }
    }
    if (!p.containsKey("company")) {
        p.put("company", getCurrentCompany());
    }
    return p;
}

From source file:gda.device.detector.mythen.MythenDetectorImpl.java

@Override
public void setCollectionTime(double collectionTime) throws DeviceException {
    super.setCollectionTime(collectionTime);
    exposureTime = BigDecimal.valueOf(collectionTime);
}

From source file:es.juntadeandalucia.panelGestion.negocio.vo.TaskVO.java

private void updateCSVProgress(BigDecimal totalSize) {
    if (taskEntity.getState().getStatus() == Status.FINISHED) {
        finishState();/*w w  w  .ja  va2 s.  c o m*/
    } else {
        // gets current data
        int readLines = fileProcessor.getNumCurrentEntry() + 1;
        long readBytes = fileProcessor.getReadBytes();

        // calculates the current process
        BigDecimal readBytesBD = BigDecimal.valueOf(readBytes);
        double progress = readBytesBD.divide(totalSize, 4, RoundingMode.HALF_UP)
                .multiply(BigDecimal.valueOf(100)).doubleValue();

        // updates the task state
        taskEntity.getState().setReadLines(readLines);
        taskEntity.getState().setProgress(progress);

        // finishes when all bytes were read
        if (readBytesBD.longValue() == totalSize.longValue()) {
            finishState();
        }
    }
}