Example usage for java.math BigDecimal BigDecimal

List of usage examples for java.math BigDecimal BigDecimal

Introduction

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

Prototype

public BigDecimal(long val) 

Source Link

Document

Translates a long into a BigDecimal .

Usage

From source file:blog.format.CheckFormatImpl.java

@Override
public boolean isBigDecimal(String str) {
    try {//from   w  w  w  .ja  v  a 2 s . co  m
        BigDecimal bigdecimal = new BigDecimal(str);
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:com.buffalokiwi.aerodrome.jet.Utils.java

/**
 * Round something with bankers rounding
 * @param d float to round//  w ww  .  j  a  v  a 2  s  .c  o  m
 * @param decimalPlace places to round to
 * @return new float
 */
public static float round(float d, int decimalPlace, RoundingMode mode) {
    BigDecimal bd = new BigDecimal(Float.toString(d));
    bd = bd.setScale(decimalPlace, mode);

    return bd.floatValue();
}

From source file:edu.mum.waa.webstore.validator.UnitsInStockValidator.java

@Override
public void validate(Object target, Errors errors) {
    Product product = (Product) target;// ww  w  .j  a v a2s.  co  m

    if (product.getUnitPrice() != null && new BigDecimal(1000).compareTo(product.getUnitPrice()) <= 0
            && product.getUnitsInStock() > 99) {
        errors.rejectValue("unitsInStock", "validator.UnitsInStockValidator.message");
    }
}

From source file:Money.java

public Money(String val) {
    this.delegate = new BigDecimal(val);
    if (delegate.scale() > 2)
        throw new IllegalArgumentException("Money can't have scale > 2");
    delegate.setScale(2);//from  w w w  . jav a 2  s. c o m
}

From source file:br.com.senac.cantinaserver.dao.ProductDAO.java

public void initDB() {

    Product product1 = new Product();
    product1.setNome("Pastel de Queijo");
    product1.setValor(new BigDecimal(6.5));
    entityManager.persist(product1);//www.j a  v a 2 s .c om

    Product product2 = new Product();
    product2.setNome("Coca-Cola");
    product2.setValor(new BigDecimal(3.3));
    entityManager.persist(product2);

    Product product3 = new Product();
    product3.setNome("Fanta Laranja");
    product3.setValor(new BigDecimal(3.0));
    entityManager.persist(product3);

    Product product4 = new Product();
    product4.setNome("Pastel de Carne");
    product4.setValor(new BigDecimal(5.5));
    entityManager.persist(product4);

    Product product5 = new Product();
    product5.setNome("Salgadinho");
    product5.setValor(new BigDecimal(2.5));
    entityManager.persist(product5);
}

From source file:com.floreantpos.util.NumberUtil.java

public static double roundToThreeDigit(double value) {
    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(3, RoundingMode.HALF_UP);
    return bd.doubleValue();
}

From source file:com.eryansky.common.web.struts2.converter.BigDecimalConverter.java

@Override
public Object convertFromString(Map context, String[] values, Class toClass) {
    if (values != null && values.length > 0) {
        if (values[0].indexOf(',') != -1) {
            return new BigDecimal(StringUtils.replace(values[0], ",", ""));
        } else {/* w  w w .  j a  v a 2  s .  c  o  m*/
            return new BigDecimal(values[0]);
        }
    }
    return null;
}

From source file:com.bstek.dorado.data.type.BigDecimalDataType.java

public Object fromText(String text) {
    if (StringUtils.isEmpty(text)) {
        return null;
    } else {/*from   w w w  .ja  v a 2 s.  co m*/
        return new BigDecimal(text);
    }
}

From source file:com.xumpy.timesheets.services.TickedJobsDetailSrv.java

public static TickedJobsDetail calculate(List<? extends TickedJobs> tickedJobs) {
    TickedJobsDetail tickedJobsDetail = new TickedJobsDetail();
    tickedJobsDetail.setTickedJobs(tickedJobs);

    if (tickedJobs.size() > 0) {
        tickedJobs = sortTickedJobs(tickedJobs);

        Date startCounterWork = null;
        Date startCounterPause = null;

        BigDecimal workedMinutes = new BigDecimal(0);
        BigDecimal pausedMinutes = new BigDecimal(0);

        for (int i = 0; i < tickedJobs.size(); i++) {
            if (i % 2 == 0) {
                if (!tickedJobs.get(i).isStarted()) {
                    tickedJobsDetail.setActualPause(new BigDecimal(-1));
                    tickedJobsDetail.setActualWorked(new BigDecimal(-1));
                    break;
                } else {
                    if (startCounterPause != null) {
                        Minutes minutes = Minutes.minutesBetween(new DateTime(startCounterPause),
                                new DateTime(tickedJobs.get(i).getTicked()));

                        pausedMinutes = pausedMinutes.add(new BigDecimal(minutes.getMinutes()));
                    }/* ww w. j  a v a2s. c  o m*/
                    startCounterWork = tickedJobs.get(i).getTicked();
                }
            } else {
                if (tickedJobs.get(i).isStarted()) {
                    tickedJobsDetail.setActualPause(new BigDecimal(-1));
                    tickedJobsDetail.setActualWorked(new BigDecimal(-1));
                    break;
                } else {
                    Minutes minutes = Minutes.minutesBetween(new DateTime(startCounterWork),
                            new DateTime(tickedJobs.get(i).getTicked()));
                    workedMinutes = workedMinutes.add(new BigDecimal(minutes.getMinutes()));
                    startCounterPause = tickedJobs.get(i).getTicked();
                }
            }

            tickedJobsDetail.setActualPause(pausedMinutes);
            tickedJobsDetail.setActualWorked(workedMinutes);
        }
    } else {
        tickedJobsDetail.setTickedJobs(tickedJobs);
        tickedJobsDetail.setActualWorked(new BigDecimal(0));
        tickedJobsDetail.setActualPause(new BigDecimal(0));
    }

    return tickedJobsDetail;
}

From source file:com.algoTrader.util.RoundUtil.java

public static BigDecimal getBigDecimal(double value, int scale) {

    if (!Double.isNaN(value)) {
        BigDecimal decimal = new BigDecimal(value);
        return decimal.setScale(scale, BigDecimal.ROUND_HALF_UP);
    } else {//from  w ww  .  ja  v  a  2s.c o  m
        return null;
    }
}