วันศุกร์ที่ 31 ตุลาคม พ.ศ. 2557

java.math.BigInteger.hashCode()

Description Of BigInteger: hashCode()

The java.math.BigInteger.hashCode() returns the hash code for this BigInteger.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("8");
     BigInteger bi2 = new BigInteger("7");
     BigInteger bi3 = new BigInteger("6");

     int h1 = bi1.hashCode();
     int h2 = bi2.hashCode();
     int h3 = bi3.hashCode();

     // show HashCode
     System.out.println("HashCode of " + bi1 + " is " + h1);
     System.out.println("HashCode of " + bi2 + " is " + h2);
     System.out.println("HashCode of " + bi3 + " is " + h3);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 30 ตุลาคม พ.ศ. 2557

java.math.BigInteger.intValue()

Description Of BigInteger: intValue()

The java.math.BigInteger.intValue() converts this BigInteger to a int

BigInteger.intValue() method returns this BigInteger converted to a int

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  // assign values to bi1, bi2
  BigInteger bi1 = new BigInteger("123");
  BigInteger bi2 = new BigInteger("-123");

  // assign int values of bi1, bi2 to i1, i2
  int i1 = bi1.intValue();
  int i2 = bi2.intValue();

  // print i1, i2 values
  System.out.println(i1); // 123
  System.out.println(i2); // -123
 }
}


yengo หรือ buzzcity

วันพุธที่ 29 ตุลาคม พ.ศ. 2557

java.math.BigInteger.longValue()

Description Of BigInteger: longValue()

The java.math.BigInteger.longValue() converts this BigInteger to a long

BigInteger.longValue() method returns this BigInteger converted to a long

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  // assign values to bi1, bi2
  BigInteger bi1 = new BigInteger("123");
  BigInteger bi2 = new BigInteger("-123");

  // assign long values of bi1, bi2 to i1, i2
  long i1 = bi1.longValue();
  long i2 = bi2.longValue();

  // print i1, i2 values
  System.out.println(i1); // 123
  System.out.println(i2); // -123
 }
}


yengo หรือ buzzcity

วันอังคารที่ 28 ตุลาคม พ.ศ. 2557

java.math.BigInteger.max(BigInteger val)

Description Of BigInteger: max(BigInteger val)

The java.math.BigInteger.max(BigInteger val) returns the maximum of this BigInteger and val.

BigInteger.max(BigInteger val) method returns the BigInteger whose value is the greater of this and val . If they are equal, either may be returned.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("2");
     BigInteger bi2 = new BigInteger("3");

     BigInteger bi3 = bi1.max(bi2);
     System.out.println(bi3);
     System.out.println(bi3.equals(bi2));
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 27 ตุลาคม พ.ศ. 2557

java.math.BigInteger.min(BigInteger val)

Description Of BigInteger: min(BigInteger val)

The java.math.BigInteger.min(BigInteger val) returns the minimum of this BigInteger and val.

BigInteger.min(BigInteger val)method returns the BigInteger whose value is the lesser of this BigInteger and val . If they are equal, either may be returned.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("2");
     BigInteger bi2 = new BigInteger("3");

     BigInteger bi3 = bi1.min(bi2);
     System.out.println(bi3);
     System.out.println(bi3.equals(bi1));
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 26 ตุลาคม พ.ศ. 2557

java.math.BigInteger.mod(BigInteger m)

Description Of BigInteger: mod(BigInteger m)

The java.math.BigInteger.mod(BigInteger m) returns a BigInteger whose value is (this mod m). This method differs from remainder in that it always returns a non-negative BigInteger

BigInteger.mod(BigInteger m) This method returns a BigInteger object whose value is this mod m.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("2");
  BigInteger bi2 = new BigInteger("3");

  System.out.println(bi1.mod(bi2)); // output 2
  System.out.println(bi2.mod(bi1)); // output 1
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 25 ตุลาคม พ.ศ. 2557

java.math.BigInteger.modInverse(BigInteger m)

Description Of BigInteger: modInverse(BigInteger m)

The java.math.BigInteger.modInverse(BigInteger m) returns a BigInteger whose value is (this-1 mod m)

BigInteger.modInverse(BigInteger m) BigInteger.modInverse(BigInteger m) method returns this-1 mod m

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("7");
  BigInteger bi2 = new BigInteger("40");

  System.out.println(bi1.mod(bi2)); // output 7
  System.out.println(bi1.modInverse(bi2)); // output 23 
  System.out.println(bi2.mod(bi1)); // output 5
  System.out.println(bi2.modInverse(bi1)); // output 3
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 24 ตุลาคม พ.ศ. 2557

java.math.BigInteger.modPow(BigInteger exponent, BigInteger m)

Description Of BigInteger: modPow(BigInteger exponent, BigInteger m)

The java.math.BigInteger.modPow(BigInteger exponent, BigInteger m) returns a BigInteger whose value is (thisexponent mod m) . (Unlike pow , this method permits negative exponents.)

BigInteger.modPow(BigInteger exponent, BigInteger m) method returns thisexponent mod m

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger exponent = new BigInteger("3");

  BigInteger bi1 = new BigInteger("2");
  BigInteger bi2 = new BigInteger("5");

  // perform modPow operation on bi1 using bi2 and exp
  BigInteger bi3 = bi1.modPow(exponent, bi2); // 2^3 % 5

  System.out.println(bi3); // output 3
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 23 ตุลาคม พ.ศ. 2557

java.math.BigInteger.multiply(BigInteger val)

Description Of BigInteger: multiply(BigInteger val)

The java.math.BigInteger.multiply(BigInteger val) returns a BigInteger whose value is (this * val)

BigInteger.multiply(BigInteger val) method returns this * val

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("4");
  BigInteger bi2 = new BigInteger("5");

  System.out.println(bi1.multiply(bi2)); // output 20
  System.out.println(bi2.multiply(bi1)); // output 20
 }
}


yengo หรือ buzzcity

วันพุธที่ 22 ตุลาคม พ.ศ. 2557

java.math.BigInteger.negate()

Description Of BigInteger: negate()

The java.math.BigInteger.negate() returns a BigInteger whose value is (-this)

BigInteger.negate() method returns -this

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("4");
  BigInteger bi2 = new BigInteger("-5");

  System.out.println(bi1.negate()); // output -4
  System.out.println(bi1); // output 4
  System.out.println(bi2.negate()); // output 5
  System.out.println(bi2); // output 5
 }
}


yengo หรือ buzzcity

วันอังคารที่ 21 ตุลาคม พ.ศ. 2557

java.math.BigInteger.nextProbablePrime()

Description Of BigInteger: nextProbablePrime()

The java.math.BigInteger.nextProbablePrime() returns the first integer greater than this BigInteger that is probably prime. The probability that the number returned by this method is composite does not exceed 2 -100 . This method will never skip over a prime when searching: if it returns p , there is no prime q such that this < q < p

BigInteger.nextProbablePrime() method returns the first integer greater than this BigInteger that is probably prime.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("3");
  BigInteger bi2 = new BigInteger("20");
  BigInteger bi3 = new BigInteger("21");

  System.out.println(bi1.nextProbablePrime()); // output 3
  System.out.println(bi2.nextProbablePrime()); // output 23
  System.out.println(bi3.nextProbablePrime()); // output 23
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 20 ตุลาคม พ.ศ. 2557

java.math.BigInteger.not()

Description Of BigInteger: not()

The java.math.BigInteger.not() returns a BigInteger whose value is (~this) . (This method returns a negative value if and only if this BigInteger is non-negative)

BigInteger.nextProbablePrime() method returns ~this

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("6");
  BigInteger bi2 = new BigInteger("-6");

  System.out.println(bi1.not()); // output -7
  System.out.println(bi2.not()); // output 5
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 19 ตุลาคม พ.ศ. 2557

java.math.BigInteger.or(BigInteger val)

Description Of BigInteger: or(BigInteger val)

The java.math.BigInteger.or(BigInteger val) returns a BigInteger whose value is (this | val) . (This method returns a negative BigInteger if and only if either this or val is negative)

BigInteger.or(BigInteger val) method returns this | val

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("3");
  BigInteger bi2 = new BigInteger("4");

  System.out.println(bi1.or(bi2)); // output 7
  System.out.println(bi2.or(bi1)); // output 7
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 18 ตุลาคม พ.ศ. 2557

java.math.BigInteger.pow(int exponent)

Description Of BigInteger: pow(int exponent)

The java.math.BigInteger.pow(int exponent) returns a BigInteger whose value is (thisexponent). Note that exponent is an integer rather than a BigInteger

BigInteger.or(BigInteger val) method returns thisexponent

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("2");

  System.out.println(bi1.pow(2)); // output 4 (2*2)
  System.out.println(bi1.pow(3)); // output 8 (2*2*2)
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 17 ตุลาคม พ.ศ. 2557

java.math.BigInteger.probablePrime(int bitLength, Random rnd)

Description Of BigInteger: probablePrime(int bitLength, Random rnd)

The java.math.BigInteger.probablePrime(int bitLength, Random rnd) returns a positive BigInteger that is probably prime, with the specified bitLength. The probability that a BigInteger returned by this method is composite does not exceed 2-100

BigInteger.probablePrime(int bitLength, Random rnd) method returns a BigInteger of bitLength bits that is probably prime

Code Example Java BigInteger

import java.math.BigInteger;
import java.util.Random;

public class BigIntegerExam {
 public static void main(String[] args) {
  int bitLength = 3;

  // create a random object
  Random rnd = new Random();

  BigInteger bi = BigInteger.probablePrime(bitLength, rnd);

  System.out.println(bi);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 16 ตุลาคม พ.ศ. 2557

java.math.BigInteger.remainder(BigInteger val)

Description Of BigInteger: remainder(BigInteger val)

The java.math.BigInteger.remainder(BigInteger val) returns a BigInteger whose value is (this % val)

BigInteger.remainder(BigInteger val) method returns this % val

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("16");
  BigInteger bi2 = new BigInteger("3");

  BigInteger bi3 = bi1.remainder(bi2);

  System.out.println(bi1); // output 16
  System.out.println(bi3); // output 1
 }
}


yengo หรือ buzzcity

วันพุธที่ 15 ตุลาคม พ.ศ. 2557

java.math.BigInteger.setBit(int n)

Description Of BigInteger: setBit(int n)

The java.math.BigInteger.setBit(int n) returns a BigInteger whose value is equivalent to this BigInteger with the designated bit set. (Computes (this | (1<<n)))

BigInteger.setBit(int n) method returns this | (1<<n)

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("4");

  BigInteger bi2 = bi1.setBit(3);

  System.out.println(bi2); // output 12
 }
}


yengo หรือ buzzcity

วันอังคารที่ 14 ตุลาคม พ.ศ. 2557

java.math.BigInteger.shiftLeft(int n)

Description Of BigInteger: shiftLeft(int n)

The java.math.BigInteger.shiftLeft(int n) BigInteger whose value is (this << n). The shift distance, n , may be negative, in which case this method performs a right shift. (Computes floor(this * 2n))

BigInteger.shiftLeft(int n) method returns this << n

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("10");

  // perform leftshift operation on bi1 using 2 and -2
  BigInteger bi2 = bi1.shiftLeft(2);
  BigInteger bi3 = bi1.shiftLeft(-2);

  System.out.println(bi2);
  System.out.println(bi3);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 13 ตุลาคม พ.ศ. 2557

java.math.BigInteger.shiftRight(int n)

Description Of BigInteger: shiftRight(int n)

The java.math.BigInteger.shiftRight(int n) BigInteger whose value is (this >> n) . Sign extension is performed. The shift distance, n , may be negative, in which case this method performs a left shift. (Computes floor(this * 2n))

BigInteger.shiftRight(int n) method returns this >> n

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("10");

  // perform rightshift operation on bi1 using 2 and -2
  BigInteger bi2 = bi1.shiftRight(2);
  BigInteger bi3 = bi1.shiftRight(-2);

  System.out.println(bi2);
  System.out.println(bi3);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 12 ตุลาคม พ.ศ. 2557

java.math.BigInteger.signum()

Description Of BigInteger: signum()

The java.math.BigInteger.signum() returns the signum function of this BigInteger

BigInteger.signum() method returns -1, 0 or 1 as the value of this BigInteger is negative, zero or positive

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("0");
  BigInteger bi2 = new BigInteger("10");
  BigInteger bi3 = new BigInteger("-10");

  // assign signum results of bi1, bi2, bi3 to i1, i2, i3
  int i1 = bi1.signum();
  int i2 = bi2.signum();
  int i3 = bi3.signum();

  // print i1, i2, i3 values
  System.out.println(i1);
  System.out.println(i2);
  System.out.println(i3);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 11 ตุลาคม พ.ศ. 2557

java.math.BigInteger.subtract(BigInteger val)

Description Of BigInteger: subtract(BigInteger val)

The java.math.BigInteger.subtract(BigInteger val) returns a BigInteger whose value is (this - val)

BigInteger.subtract(BigInteger val) method returns this - val

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("5");
  BigInteger bi2 = new BigInteger("3");

  // assign difference of bi1 and bi2 to bi3
  BigInteger bi3 = bi1.subtract(bi2);

  System.out.println(bi3);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 10 ตุลาคม พ.ศ. 2557

java.math.BigInteger.testBit(int n)

Description Of BigInteger: testBit(int n)

The java.math.BigInteger.testBit(int n) returns true if and only if the designated bit is set. (Computes ((this & (1<<n)) != 0))

BigInteger.testBit(int n) method returns true if and only if the designated bit is set

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi = new BigInteger("10");

  Boolean b1 = bi.testBit(2);
  Boolean b2 = bi.testBit(3);
  
  // print b1, b2 values
  System.out.println(b1);
  System.out.println(b2);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 9 ตุลาคม พ.ศ. 2557

java.math.BigInteger.toString()

Description Of BigInteger: toString()

The java.math.BigInteger.toString() returns the decimal String representation of this BigInteger. The digit-to-character mapping provided by Character.forDigit is used, and a minus sign is prepended if appropriate. (This representation is compatible with the (String) constructor, and allows for String concatenation with Java's + operator)

BigInteger.toString() method returns decimal String representation of this BigInteger

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("1234");
  BigInteger bi2 = new BigInteger("-1234");

  System.out.println(bi1.toString()); // output 1234
  System.out.println(bi2.toString()); // output -1234
 }
}


yengo หรือ buzzcity

วันพุธที่ 8 ตุลาคม พ.ศ. 2557

java.math.BigInteger.toString(int radix)

Description Of BigInteger: toString(int radix)

The java.math.BigInteger.toString(int radix) returns the String representation of this BigInteger in the given radix. If the radix is outside the range from Character.MIN_RADIX to Character.MAX_RADIX inclusive, it will default to 10 (as is the case for Integer.toString ). The digit-to-character mapping provided by Character.forDigit is used, and a minus sign is prepended if appropriate. (This representation is compatible with the (String, int) constructor)

BigInteger.toString(int radix) method returns String representation of this BigInteger in the given radix

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("16");
  BigInteger bi2 = new BigInteger("-16");

  System.out.println(bi1.toString(8));
  System.out.println(bi2.toString(2));
 }
}


yengo หรือ buzzcity

วันอังคารที่ 7 ตุลาคม พ.ศ. 2557

java.math.BigInteger.valueOf(long val)

Description Of BigInteger: valueOf(long val)

The java.math.BigInteger.valueOf(long val) returns a BigInteger whose value is equal to that of the specified long . This "static factory method" is provided in preference to a ( long ) constructor because it allows for reuse of frequently used BigIntegers

BigInteger.valueOf(long val) method returns a BigInteger with the specified value

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = BigInteger.valueOf(54L);
  BigInteger bi2 = BigInteger.valueOf(55);
  
  Long ln = new Long(56);
  BigInteger bi3 = BigInteger.valueOf(ln);
  
  System.out.println(bi1);
  System.out.println(bi2);
  System.out.println(bi3);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 6 ตุลาคม พ.ศ. 2557

java.math.BigInteger.xor(BigInteger val)

Description Of BigInteger: xor(BigInteger val)

The java.math.BigInteger.xor(BigInteger val) returns a BigInteger whose value is (this ^ val) . (This method returns a negative BigInteger if and only if exactly one of this and val are negative)

BigInteger.xor(BigInteger val) method returns this ^ val

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("8");
  BigInteger bi2 = new BigInteger("2");

  // perform xor on bi1, bi2 and assign result to bi3
  BigInteger bi3 = bi1.xor(bi2);

  System.out.println(bi3);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 5 ตุลาคม พ.ศ. 2557

java.math.BigDecimal.abs()

Description Of BigDecimal: abs()

The java.math.BigDecimal.abs() returns a BigDecimal whose value is the absolute value of this BigDecimal, and whose scale is this.scale().

BigDecimal.abs() This method returns the absolute value of the called value i.e abs(this).

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal de1 = new BigDecimal("456");
  BigDecimal de2 = new BigDecimal("-456");
  System.out.println("Absolute value of " + de1 + " is " + de1.abs()); // Absolute value of 456 is 456
  System.out.println("Absolute value of " + de2 + " is " + de2.abs()); // Absolute value of -456 is 456
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 4 ตุลาคม พ.ศ. 2557

java.math.BigDecimal.abs(MathContext mc)

Description Of BigDecimal: abs(MathContext mc)

The java.math.BigDecimal.abs(MathContext mc) returns a BigDecimal whose value is the absolute value of this BigDecimal , with rounding according to the context settings.

BigDecimal.abs(MathContext mc) method returns abs(this) , rounded as necessary

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  MathContext mc = new MathContext(3);
  MathContext mc1 = new MathContext(4);

  BigDecimal bg1 = new BigDecimal("123.1234");

  // assign absolute value of bg1 to bg2 rounded to 2 precision using mc
  BigDecimal bg2 = bg1.abs(mc);

  // assign absolute value of bg1 to bg3 rounded to 4 precision using mc1
  BigDecimal bg3 = bg1.abs(mc1);

  System.out.println(bg2);
  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 3 ตุลาคม พ.ศ. 2557

java.math.BigDecimal.add(BigDecimal augend)

Description Of BigDecimal: add(BigDecimal augend)

The java.math.BigDecimal.add(BigDecimal augend) returns a BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale())

BigDecimal.add(BigDecimal augend) method returns this + augend

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("12.345");
  BigDecimal bg2 = new BigDecimal("20.123");

  // print bg1 and bg2 value
  System.out.println("Object Value is " + bg1);
  System.out.println("Augend value is " + bg2);

  // perform add operation on bg1 with augend bg2
  BigDecimal bg3 = bg1.add(bg2);

  // print bg3 value
  System.out.println("Result is " + bg3);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 2 ตุลาคม พ.ศ. 2557

java.math.BigDecimal.add(BigDecimal augend, MathContext mc)

Description Of BigDecimal: add(BigDecimal augend, MathContext mc)

The java.math.BigDecimal.add(BigDecimal augend, MathContext mc) returns a BigDecimal whose value is (this + augend) , with rounding according to the context settings. If either number is zero and the precision setting is nonzero then the other number, rounded if necessary, is used as the result

BigDecimal.add(BigDecimal augend, MathContext mc) method returns this + augend , rounded as necessary.

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.MathContext;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("12.345");
     BigDecimal bg2 = new BigDecimal("23.456");

     System.out.println("Object Value is " + bg1);
     System.out.println("Augend value is " + bg2);

     // create MathContext object with 4 precision
     MathContext mc = new MathContext(4);

     // perform add operation on bg1 with augend bg2 and context mc
     BigDecimal bg3 = bg1.add(bg2, mc);

     System.out.println("Result is " + bg3);
 }
}


yengo หรือ buzzcity

วันพุธที่ 1 ตุลาคม พ.ศ. 2557

java.math.BigDecimal.byteValueExact()

Description Of BigDecimal: byteValueExact()

The java.math.BigDecimal.byteValueExact() converts this BigDecimal to a byte , checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a byte result then an ArithmeticException is thrown

BigDecimal.xor(BigInteger val) method returns this BigDecimal converted to a byte

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  // assign values to bg1 and bg2
  BigDecimal bg1 = new BigDecimal("-4");
  BigDecimal bg2 = new BigDecimal("2");

  byte i1 = bg1.byteValueExact();
  byte i2 = bg2.byteValueExact();

  // print i1,i2 values
  System.out.println(i1);
  System.out.println(i2);
 }
}


yengo หรือ buzzcity