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

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("123.23");
    BigDecimal bg2 = new BigDecimal("12323");

    BigDecimal bg3 = bg1.movePointLeft(3); // 3 points left
    BigDecimal bg4 = bg2.movePointLeft(-2);// 2 points right

    // print bg3, bg4 values
    System.out.println(bg3);/*from w  ww.  ja va 2 s  . c om*/
    System.out.println(bg4);
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("123.67");
    BigDecimal bg2 = new BigDecimal("1234567890987654");

    // assign the long value of bg1 and bg2 to l1,l2 respectively
    long l1 = bg1.longValue();
    long l2 = bg2.longValue();

    System.out.println(l1);/* w ww  . j ava 2s .  c om*/
    System.out.println(l2);
}

From source file:BigDec.java

public static void main(String args[]) {
    BigDecimal rate = new BigDecimal(".03251234");
    BigDecimal months = new BigDecimal("12");
    BigDecimal monthlyRate = rate.divide(months, BigDecimal.ROUND_HALF_DOWN);
    System.out.println("Annual rate : " + rate);
    System.out.println("Monthly rate: " + monthlyRate);
    BigDecimal balance = new BigDecimal("10000.0000");
    for (int i = 0; i < 12; i++) {
        BigDecimal interest = balance.multiply(monthlyRate);
        balance = balance.add(interest);
        System.out.println("Balance: " + balance);
    }/*from w  w w  . j  ava  2  s  .c om*/
}

From source file:Main.java

public static void main(String[] args) {

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

    // bg2 divided by bg1 gives bg3 as remainder
    BigDecimal bg3 = bg1.remainder(bg2);

    String str = "The remainder is " + bg3;

    // print the value of bg3
    System.out.println(str);//from   w  w  w  .  j a v a  2s. c o  m
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("40");
    BigDecimal bg2 = new BigDecimal("4E+1");

    // assign the exact int value of bg1 and bg2 to i1,i2 respectively
    int i1 = bg1.intValueExact();
    int i2 = bg2.intValueExact();

    // print i1,i2 values
    System.out.println(i1);/*from  w ww . j  av  a  2 s .  com*/
    System.out.println(i2);
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("-999999");
    BigDecimal bg2 = new BigDecimal("3.3E+10");

    // assign the long value of bg1 and bg2 to l1,l2 respectively
    long l1 = bg1.longValueExact();
    long l2 = bg2.longValueExact();

    // print l1,l2 values
    System.out.println(l1);//from w  w  w.  j a  v a2 s .c  om
    System.out.println(l2);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BigDecimal bd1 = new BigDecimal("123456789.0123456890");

    bd1 = bd1.negate();/*from  w ww .  j  a va 2 s  .  co  m*/

}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("100.123");
    BigDecimal bg2 = new BigDecimal("50.56");

    // subtract bg1 with bg2 and assign result to bg3
    BigDecimal bg3 = bg1.subtract(bg2);

    String str = "The Result of Subtraction is " + bg3;

    // print bg3 value
    System.out.println(str);//  w w  w  .  ja  va  2 s. c  o  m
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("25.00");
    BigDecimal bg2 = new BigDecimal("25.00");
    BigDecimal bg3 = new BigDecimal("25");

    // assign the result of equals method to b1, b2
    Boolean b1 = bg1.equals(bg2);
    Boolean b2 = bg1.equals(bg3);

    System.out.println(b1);/*w w  w. j ava 2  s  .  c  o  m*/
    System.out.println(b2);
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("1234");

    // assign a larger value to bg2
    BigDecimal bg2 = new BigDecimal("123456789098765");

    // assign the int value of bg1 and bg2 to i1,i2 respectively
    int i1 = bg1.intValue();
    int i2 = bg2.intValue();

    System.out.println(i1);/*from w  w w .j a  v a 2s .  c om*/
    System.out.println(i2);
}