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:Main.java

/**
 * Write a {@link BigDecimal} value into XML output,
 * that matches the type of the "thermalCharacteristic" element.
 *
 * @param value/*from w  w  w  . java 2s. c  o m*/
 * value to write
 *
 * @return
 * XML string
 *
 * @throws IllegalArgumentException
 * if a validation error occured
 */
public static String printThermalCharacteristic(BigDecimal value) {
    return printDecimal(value, BigDecimal.ZERO, new BigDecimal("2000"), 3, false);
}

From source file:Main.java

public static BigDecimal calculatePercent(Integer numerator, Integer denominator) {
    BigDecimal result = BigDecimal.ZERO;
    if (numerator != null && denominator != null) {
        return calculatePercent(new BigDecimal(numerator.intValue()), new BigDecimal(denominator.intValue()));
    }//from   w w w  . ja  v a  2 s.c  o  m
    return result;
}

From source file:be.error.rpi.ebus.Support.java

public static BigDecimal decodeDATA2c(byte[] data) {
    return new BigDecimal(decodeInt(data)).divide(new BigDecimal(16)).setScale(2, HALF_UP);
}

From source file:Main.java

public static double round(double v, int scale) {
    if (scale < 0) {
        throw new IllegalArgumentException("The scale must be a positive integer or zero");
    }/*from w  w  w  . j  a  v  a2 s .c o m*/
    BigDecimal b = new BigDecimal(Double.toString(v));
    BigDecimal one = new BigDecimal("1");
    return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}

From source file:Main.java

/**
 * Parse currency amount conversion rate string
 * <p/>//from  w  ww. ja  v  a 2 s  . c o  m
 * Suitble for parse fields 10 and 11
 *
 * @param convRate amount conversation rate
 * @return parsed currency amount conversation rate
 * @throws IllegalArgumentException
 */
public static double parseAmountConversionRate(String convRate) {
    if (convRate == null || convRate.length() != 8)
        throw new IllegalArgumentException("Invalid amount converion rate argument: '" + convRate + "'");
    BigDecimal bd = new BigDecimal(convRate);
    int pow = bd.movePointLeft(7).intValue();
    bd = new BigDecimal(convRate.substring(1));
    return bd.movePointLeft(pow).doubleValue();
}

From source file:com.fengduo.bee.commons.util.NumberParser.java

/**
 * /*from  ww w.ja v a 2s .  c  o  m*/
 * 
 * @return
 */
public static String fromUsage(long free, long total) {
    Double d = new BigDecimal(free * 100 / total).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
    return String.valueOf(d);
}

From source file:gov.nih.nci.calims2.ui.administration.customerservice.serviceitem.ServiceItemHelper.java

/**
 * Give the sub total value from quantity and rate.
 * //  ww w.jav  a  2  s.  com
 * @param row The ServiceItem type
 * @return The sub total corresponding to the given value. Returns null if the subtotal can not be calculated
 */
public static BigDecimal getsubTotalValue(ServiceItem row) {
    Quantity quantity = row.getQuantity();
    Rate rate = row.getServiceItemRate();
    if (quantity == null || StringUtils.isBlank(quantity.getValue()) || rate == null
            || rate.getQuantity() == null || StringUtils.isBlank(rate.getQuantity().getValue())) {
        return null;
    }
    BigDecimal bigDecQty = new BigDecimal(quantity.getValue());
    BigDecimal bigDecRate = new BigDecimal(rate.getQuantity().getValue());
    BigDecimal subtotal = bigDecQty.multiply(bigDecRate);
    return subtotal;
}

From source file:Main.java

/**
 * Round the given value to the specified number of decimal places. The
 * value is rounded using the given method which is any method defined in
 * {@link BigDecimal}.//from ww  w .j av a2  s . c  om
 * 
 * @param x the value to round.
 * @param scale the number of digits to the right of the decimal point.
 * @param roundingMethod the rounding method as defined in
 *        {@link BigDecimal}.
 * @return the rounded value.
 * @since 1.1
 */
public static double round(double x, int scale, int roundingMethod) {
    try {
        return (new BigDecimal(Double.toString(x)).setScale(scale, roundingMethod)).doubleValue();
    } catch (NumberFormatException ex) {
        if (Double.isInfinite(x)) {
            return x;
        } else {
            return Double.NaN;
        }
    }
}

From source file:com.mylaensys.dhtmlx.adapter.test.TestForm.java

@BeforeClass
public static void initialize() throws ParseException {
    object = new TestObject(1L, "10/09/2011", "First String of Text", 100, new BigDecimal(100.0), true);
}

From source file:com.mobileman.projecth.web.util.NumUtils.java

public static BigDecimal convert2decimal(String str) {
    try {//from  w  w  w .  j  a  v a 2 s . c o m
        if (StringUtils.isNotBlank(str)) {
            return new BigDecimal(str);
        }
    } catch (Exception ex) {
    }
    return null;
}