Example usage for java.math BigDecimal divide

List of usage examples for java.math BigDecimal divide

Introduction

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

Prototype

public BigDecimal divide(BigDecimal divisor) 

Source Link

Document

Returns a BigDecimal whose value is (this / divisor) , and whose preferred scale is (this.scale() - divisor.scale()) ; if the exact quotient cannot be represented (because it has a non-terminating decimal expansion) an ArithmeticException is thrown.

Usage

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("45");
    BigDecimal bg2 = new BigDecimal("5");

    BigDecimal bg3 = bg1.divide(bg2); // divide bg1 with bg2

    System.out.println(bg3);//from   ww  w. j  a  v  a 2 s  .c  o  m
}

From source file:MainClass.java

public static void main(String argv[]) {
    BigDecimal first = new BigDecimal("3419229223372036854775807.23343");
    BigDecimal second = new BigDecimal("2.0");
    System.out.println(first.add(second));
    System.out.println(first.subtract(second));
    System.out.println(first.divide(second));
    System.out.println(first.equals(second));
    System.out.println(first.abs());
    System.out.println(first.max(second));
    System.out.println(first.min(second));
    System.out.println(first.remainder(second));
}

From source file:Main.java

public static void main(String[] args) {
    BigDecimal decimalA = new BigDecimal("123456789012345");
    BigDecimal decimalB = new BigDecimal("10");

    decimalA = decimalA.add(decimalB);/*from  w w w. j ava2  s. co m*/
    System.out.println("decimalA = " + decimalA);

    decimalA = decimalA.multiply(decimalB);
    System.out.println("decimalA = " + decimalA);

    decimalA = decimalA.subtract(decimalB);
    System.out.println("decimalA = " + decimalA);

    decimalA = decimalA.divide(decimalB);
    System.out.println("decimalA = " + decimalA);

    decimalA = decimalA.pow(2);
    System.out.println("decimalA = " + decimalA);

    decimalA = decimalA.negate();
    System.out.println("decimalA = " + decimalA);
}

From source file:Main.java

public static BigDecimal addVatAmount(BigDecimal percentage, BigDecimal amount) {
    return amount.multiply(percentage.divide(HUNDRED));
}

From source file:Main.java

/**
 * Get the given value in satoshis as a string on the form "10.12345".
 * <p>/*from   w  w  w  .  j a v a2s . c om*/
 * This method only returns necessary decimal points to tell the exact value.
 * If you wish to have all 8 digits use
 * {@link CoinUtil#fullValueString(long)}
 * 
 * @param value
 *           The number of satoshis
 * @return The given value in satoshis as a string on the form "10.12345".
 */
public static String valueString(long value) {
    BigDecimal d = BigDecimal.valueOf(value);
    d = d.divide(ONE_BTC_IN_SATOSHIS);
    return d.toPlainString();
}

From source file:Main.java

public static String change2String(int cent) {
    BigDecimal decimal = new BigDecimal(cent);
    BigDecimal decimal1 = new BigDecimal(100);
    return decimal.divide(decimal1).toString();
}

From source file:Main.java

public static double divide(double d1, double d2) {
    BigDecimal bd1 = new BigDecimal(Double.toString(d1));
    BigDecimal bd2 = new BigDecimal(Double.toString(d2));
    return bd1.divide(bd2).doubleValue();
}

From source file:Main.java

/**
 * Parses amount strings from GnuCash XML into {@link java.math.BigDecimal}s
 * @param amountString String containing the amount
 * @return BigDecimal with numerical value
 *//*from   w ww. j a v  a2  s  .co  m*/
public static BigDecimal parseMoney(String amountString) {
    String[] tokens = amountString.split("/");
    BigDecimal numerator = new BigDecimal(tokens[0]);
    BigDecimal denominator = new BigDecimal(tokens[1]);

    return numerator.divide(denominator);
}

From source file:com.creditcloud.ump.model.ump.utils.UmpUtils.java

public static BigDecimal fromCents(String amountInCents) {
    BigDecimal amount = NumberUtils.parse(amountInCents).setScale(2);

    return amount.divide(HUNDRED);
}

From source file:org.cryptomath.util.NumberUtil.java

public static String spillFloats(String value, final int pTimes) {
    String result;/*from w  w w .jav a 2s .  com*/
    if (value.matches("[\\d]*")) {

        BigDecimal bd = new BigDecimal(value);
        int f = CryptoConfigSpec.getInstance().getMathConfig().getFractions();
        bd = bd.divide(new BigDecimal("10").pow(f * pTimes));

        result = bd.toString();
    } else {
        throw new NumberFormatException(MessageFormat.format("Invalid argument {0}", value));
    }
    return result;
}