Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: some maths operation using ‘BigDecimal’ class

Java: some maths operation using 'BigDecimal' class
{filelink=11212}

import java.math.BigDecimal;
public class BigDecMath
 {
  public static void main(String[] args)
  	{
    BigDecimal bd1 = new BigDecimal("12525.14");
    BigDecimal bd2 = new BigDecimal("20");
    // Addition
    bd1 = bd1.add(bd2);
    System.out.println("bd1 = " + bd1);
    // Multiplication
    bd1 = bd1.multiply(bd2);
    System.out.println("bd1 = " + bd1);
    // Substraction
    bd1 = bd1.subtract(bd2);
    System.out.println("bd1 = " + bd1);
    // Division
    bd1 = bd1.divide(bd2);
    System.out.println("bd1 = " + bd1);
    // Power
    bd1 = bd1.pow(2);
    System.out.println("bd1 = " + bd1);
    bd1 = bd1.negate();
    System.out.println("bd1 = " + bd1);
  }
}

Users who found this page were searching for:

  • factorial of number using until in perl
  • python get local hostname
  • python read whole file
  • factorial of number using perl
  • python get current directory
  • how to use hash in perl

No comments yet.

Leave a Comment