Example usage for java.math BigDecimal ZERO

List of usage examples for java.math BigDecimal ZERO

Introduction

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

Prototype

BigDecimal ZERO

To view the source code for java.math BigDecimal ZERO.

Click Source Link

Document

The value 0, with a scale of 0.

Usage

From source file:Main.java

public static void main(String[] args) {

    System.out.println(BigDecimal.ZERO);
}

From source file:to.sparks.mtgox.example.HowToWithdrawBitcoins.java

/** *
 * Send the entire bitcoin balance of a MtGox account to a destination
 * bitcoin address.//from   w w w .ja va  2s  . co  m
 * OTP is not supported! Please turn off Yubikey/OTP
 *
 * @param args The destination bitcoin address
 * @throws Exception OTP is not supported! Please turn off Yubikey/OTP
 */
public static void main(String[] args) throws Exception {

    // Obtain a $USD instance of the API
    ApplicationContext context = new ClassPathXmlApplicationContext("to/sparks/mtgox/example/Beans.xml");
    MtGoxHTTPClient mtGoxAPI = (MtGoxHTTPClient) context.getBean("mtgoxUSD");

    HashMap<String, Wallet> wallets = mtGoxAPI.getAccountInfo().getWallets();
    Wallet btcWallet = wallets.get("BTC");
    MtGoxBitcoin mtgoxBalance = (MtGoxBitcoin) btcWallet.getBalance();
    logger.log(Level.INFO, "MtGox account balance: BTC {0}", mtgoxBalance.toPlainString());
    if (mtgoxBalance.compareTo(BigDecimal.ZERO) > 0) {

        MtGoxBitcoin fee = new MtGoxBitcoin(0.0005D); // Transaction fee
        MtGoxBitcoin transferAmount = new MtGoxBitcoin(mtgoxBalance.subtract(fee));

        if (transferAmount.compareTo(BigDecimal.ZERO) > 0) {
            logger.log(Level.INFO, "Transferring BTC {0} to bitcoin address {1} and paying fee {2}",
                    new Object[] { transferAmount.toPlainString(), args[0], fee.toPlainString() });
            SendBitcoinsTransaction trx = mtGoxAPI.sendBitcoins(args[0], transferAmount, fee, true, false);
            logger.log(Level.INFO, "Transfer success.  trx: {0}", trx.getTrx());
        }
    }
}

From source file:Main.java

public static BigDecimal calculateDiscountAmt(BigDecimal Discount, BigDecimal DiscountAmt) {
    if (DiscountAmt == null || Discount.compareTo(BigDecimal.ZERO) == 0)
        return BigDecimal.ZERO;
    else {//from  w ww  .j av a 2  s  .  c  o m
        BigDecimal discountPerc = Discount.divide(new BigDecimal(100));
        return DiscountAmt.multiply(discountPerc);
    }
}

From source file:Main.java

/**
 * H = -[0.5 * lg(0.5) + 0.4*lg(0.4) + 0.1*lg(0.1)]
 *//* w  w  w.  j  a  va2s .co m*/
public static BigDecimal calculateEntropy(double... probabilities) {
    BigDecimal res = BigDecimal.ZERO;

    for (double singleProbability : probabilities) {

        BigDecimal singleEntropy = BigDecimal.valueOf(singleProbability)
                .multiply(BigDecimal.valueOf(lg2(singleProbability)));

        res = res.add(singleEntropy);
    }

    return res.negate().setScale(ENTROPY_SCALE, BigDecimal.ROUND_HALF_UP);
}

From source file:Main.java

public static BigDecimal max(final List<BigDecimal> list) {
    BigDecimal max = BigDecimal.ZERO;
    for (final BigDecimal item : list) {
        if (item.compareTo(max) > 0)
            max = item;/*from   w  w  w  .ja  v  a 2 s  .c  o m*/
    }
    return max;
}

From source file:Main.java

public static BigDecimal avg(final List<BigDecimal> list) {
    return list.size() > 0 ? sum(list).setScale(10, RoundingMode.HALF_UP).divide(new BigDecimal(list.size()),
            RoundingMode.HALF_UP) : BigDecimal.ZERO;
}

From source file:Main.java

public static BigDecimal calculateDivide(BigDecimal numerator, BigDecimal denominator) {
    BigDecimal result = BigDecimal.ZERO;
    if (denominator.compareTo(BigDecimal.ZERO) != 0) {
        result = numerator.divide(denominator, 3, BigDecimal.ROUND_HALF_UP);
    }/* w w  w.  j a  v  a  2  s.  co  m*/
    return result;
}

From source file:Main.java

/**
 * NOTE: Arithmetic operations in primitive types may lead to arithmetic overflow. To retain
 * precision, BigDecimal objects are used.
 *
 * @param rgb//from   w ww . j  a v a2s . co  m
 * @return
 */
public static int[] convertRGB_8_8_8_To_HSB_32_32_32(int[] rgb) {
    int[] hsb = new int[3];
    int maxChroma = Math.max(Math.max(rgb[0], rgb[1]), rgb[2]);
    int minChroma = Math.min(Math.min(rgb[0], rgb[1]), rgb[2]);
    int diff = maxChroma - minChroma;

    // Hue
    BigDecimal hue;
    if (diff == 0) {
        hue = BigDecimal.ZERO;
    } else if (maxChroma == rgb[0]) {
        float tmp = (rgb[1] - rgb[2]) / (float) diff;
        if (tmp < 0) {
            tmp += 6 * Math.ceil(-tmp / 6.0);
        } else {
            tmp -= 6 * Math.floor(tmp / 6.0);
        }
        hue = BigDecimal.valueOf(tmp);
    } else if (maxChroma == rgb[1]) {
        hue = BigDecimal.valueOf((rgb[2] - rgb[0]) / (float) diff + 2);
    } else {
        hue = BigDecimal.valueOf((rgb[0] - rgb[1]) / (float) diff + 4);
    }
    // [0, 360] -> [0, 0xffffffff]
    hue = hue.multiply(BigDecimal.valueOf(0xffffffffL));
    hue = hue.divide(BigDecimal.valueOf(6), RoundingMode.FLOOR);
    hsb[0] = ByteBuffer.allocate(8).putLong(hue.longValue()).getInt(4);

    // Saturation
    if (maxChroma == 0) {
        hsb[1] = 0;
    } else {
        // [0, 1] -> [0, 0xffffffff]
        BigDecimal sat = BigDecimal.valueOf(diff);
        sat = sat.multiply(BigDecimal.valueOf(0xffffffffL));
        sat = sat.divide(BigDecimal.valueOf(maxChroma), RoundingMode.FLOOR);
        hsb[1] = ByteBuffer.allocate(8).putLong(sat.longValue()).getInt(4);
    }

    // Brightness
    // [0, 255] -> [0, 0xffffffff]
    BigDecimal brightness = BigDecimal.valueOf(maxChroma);
    brightness = brightness.multiply(BigDecimal.valueOf(0xffffffffL));
    brightness = brightness.divide(BigDecimal.valueOf(0xffL), RoundingMode.FLOOR);
    hsb[2] = ByteBuffer.allocate(8).putLong(brightness.longValue()).getInt(4);

    return hsb;
}

From source file:Main.java

public static BigDecimal calculatePercent(BigDecimal numerator, BigDecimal denominator) {
    BigDecimal result = BigDecimal.ZERO;
    if (numerator != null && denominator != null && (denominator.compareTo(BigDecimal.ZERO) != 0)) {
        result = numerator.divide(denominator, 3, BigDecimal.ROUND_HALF_UP).movePointRight(2);
    }//from   w  w w.  ja  v a  2s.  co m
    return result;
}

From source file:Main.java

public static BigDecimal setDecimalDigit(BigDecimal number, int digit, boolean setNullIndicator) {
    BigDecimal returnNum = BigDecimal.ZERO;
    if (number != null) {
        if ((number.compareTo(BigDecimal.ZERO) == 0) && setNullIndicator) {
            return null;
        }/*from  w  ww. j  av  a2  s  . c o m*/
        returnNum = number.setScale(digit, BigDecimal.ROUND_HALF_UP);
    }
    return returnNum;
}