วันอังคารที่ 30 กันยายน พ.ศ. 2557

java.math.BigDecimal.xor(BigInteger val)

Description Of BigDecimal: compareTo(BigDecimal val)

The java.math.BigDecimal.xor(BigInteger val) compares this BigDecimal with the specified BigDecimal . Two BigDecimal objects that are equal in value but have a different scale (like 2.0 and 2.00) are considered equal by this method. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y) < op > 0) , where < op > is one of the six comparison operators.

BigDecimal.compareTo(BigDecimal val) method returns -1, 0, or 1 as this BigDecimal is numerically less than, equal to, or greater than val

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  int res = bg1.compareTo(bg2); // compare bg1 with bg2

  if (res == 0) {
   System.out.println("Both values are equal");
  } else if (res == 1) {
   System.out.println("First Value is greater");
  } else if (res == -1) {
   System.out.println("Second value is greater");
  }
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 29 กันยายน พ.ศ. 2557

java.math.BigDecimal.divide(BigDecimal divisor)

Description Of BigDecimal: divide(BigDecimal divisor)

The java.math.BigDecimal.divide(BigDecimal divisor) 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.

BigDecimal.divide(BigDecimal divisor) method returns this / divisor

Code Example Java BigDecimal

import java.math.BigDecimal;

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

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

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 28 กันยายน พ.ศ. 2557

java.math.BigDecimal.divide(BigDecimal divisor, int roundingMode)

Description Of BigDecimal: divide(BigDecimal divisor, int roundingMode)

The java.math.BigDecimal.divide(BigDecimal divisor, int roundingMode) returns a BigDecimal whose value is (this / divisor) , and whose scale is this.scale() . If rounding must be performed to generate a result with the given scale, the specified rounding mode is applied.

BigDecimal.divide(BigDecimal divisor, int roundingMode) method returns this / divisor

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  System.out.println(bg1.divide(bg2, BigDecimal.ROUND_UP));
  System.out.println(bg1.divide(bg2, BigDecimal.ROUND_DOWN));
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 27 กันยายน พ.ศ. 2557

java.math.BigDecimal.divide(BigDecimal divisor, int scale, int roundingMode)

Description Of BigDecimal: divide(BigDecimal divisor, int scale, int roundingMode)

The java.math.BigDecimal.divide(BigDecimal divisor, int scale, int roundingMode) returns a BigDecimal whose value is (this / divisor) , and whose scale is as specified. If rounding must be performed to generate a result with the specified scale, the specified rounding mode is applied.

BigDecimal.divide(BigDecimal divisor, int scale, int roundingMode) method returns this / divisor

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  System.out.println(bg1.divide(bg2, 2, BigDecimal.ROUND_UP));
  System.out.println(bg1.divide(bg2, 1, BigDecimal.ROUND_DOWN));
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 26 กันยายน พ.ศ. 2557

java.math.BigDecimal.divide(BigDecimal divisor, int scale, RoundingMode roundingMode)

Description Of BigDecimal: divide(BigDecimal divisor, int scale, RoundingMode roundingMode)

The java.math.BigDecimal.divide(BigDecimal divisor, int scale, RoundingMode roundingMode) returns a BigDecimal whose value is (this / divisor) , and whose scale is as specified. If rounding must be performed to generate a result with the specified scale, the specified rounding mode is applied.

BigDecimal.xor(BigInteger val) method returns this / divisor

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.RoundingMode;

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

  System.out.println(bg1.divide(bg2, 2, RoundingMode.UP));
  System.out.println(bg1.divide(bg2, 1, RoundingMode.DOWN));
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 25 กันยายน พ.ศ. 2557

java.math.BigDecimal.divide(BigDecimal divisor, MathContext mc)

Description Of BigDecimal: divide(BigDecimal divisor, MathContext mc)

The java.math.BigDecimal.divide(BigDecimal divisor, MathContext mc) returns a BigDecimal whose value is (this / divisor) , with rounding according to the context settings

BigDecimal.divide(BigDecimal divisor, MathContext mc) method returns this / divisor , 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("10");
  BigDecimal bg2 = new BigDecimal("3");

  MathContext mc = new MathContext(3);

  BigDecimal bg3 = bg1.divide(bg2, mc);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันพุธที่ 24 กันยายน พ.ศ. 2557

java.math.BigDecimal.divide(BigDecimal divisor, RoundingMode roundingMode)

Description Of BigDecimal: divide(BigDecimal divisor, RoundingMode roundingMode)

The java.math.BigDecimal.divide(BigDecimal divisor, RoundingMode roundingMode) returns a BigDecimal whose value is (this / divisor) , and whose scale is this.scale() . If rounding must be performed to generate a result with the given scale, the specified rounding mode is applied.

BigDecimal.divide(BigDecimal divisor, RoundingMode roundingMode) method returns this / divisor

Code Example Java BigDecimal

import java.math.BigDecimal;
import java.math.RoundingMode;

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

  BigDecimal bg3 = bg1.divide(bg2, RoundingMode.UP);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 23 กันยายน พ.ศ. 2557

java.math.BigDecimal.divideAndRemainder(BigDecimal divisor)

Description Of BigDecimal: divideAndRemainder(BigDecimal divisor)

The java.math.BigDecimal.divideAndRemainder(BigDecimal divisor) returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

Note that if both the integer quotient and remainder are needed, this method is faster than using the divideToIntegralValue and remainder methods separately because the division need only be carried out once.

BigDecimal.divideAndRemainder(BigDecimal divisor) method returns a two element BigDecimal array: the quotient (the result of divideToIntegralValue ) is the initial element and the remainder is the final element.

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  BigDecimal bg[] = bg1.divideAndRemainder(bg2);

     System.out.println("Quotient is " + bg[0]);
     System.out.println("Remainder is " + bg[1]);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 22 กันยายน พ.ศ. 2557

java.math.BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc)

Description Of BigDecimal: divideAndRemainder(BigDecimal divisor, MathContext mc)

The java.math.BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc) returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands calculated with rounding according to the context settings.

Note that if both the integer quotient and remainder are needed, this method is faster than using the divideToIntegralValue and remainder methods separately because the division need only be carried out once.

BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc) method returns a two element BigDecimal array: the quotient (the result of divideToIntegralValue ) is the initial element and the remainder is the final element.

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("1000.12");
  BigDecimal bg2 = new BigDecimal("332.32");

  MathContext mc = new MathContext(3);
  
  BigDecimal bg[] = bg1.divideAndRemainder(bg2, mc);

     System.out.println("Quotient is " + bg[0]);
     System.out.println("Remainder is " + bg[1]);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 21 กันยายน พ.ศ. 2557

java.math.BigDecimal.divideToIntegralValue(BigDecimal divisor)

Description Of BigDecimal: divideToIntegralValue(BigDecimal divisor)

The java.math.BigDecimal.divideToIntegralValue(BigDecimal divisor) returns a BigDecimal whose value is the integer part of the quotient (this / divisor) rounded down. The preferred scale of the result is (this.scale() - divisor.scale())

BigDecimal.divideToIntegralValue(BigDecimal divisor) method returns The integer part of this / divisor

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  BigDecimal bg3 = bg1.divideToIntegralValue(bg2);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 20 กันยายน พ.ศ. 2557

java.math.BigDecimal.divideToIntegralValue(BigDecimal divisor, MathContext mc)

Description Of BigDecimal: divideToIntegralValue(BigDecimal divisor, MathContext mc)

The java.math.BigDecimal.divideToIntegralValue(BigDecimal divisor, MathContext mc) returns a BigDecimal whose value is the integer part of (this / divisor) . Since the integer part of the exact quotient does not depend on the rounding mode, the rounding mode does not affect the values returned by this method. The preferred scale of the result is (this.scale() - divisor.scale()) . An ArithmeticException is thrown if the integer part of the exact quotient needs more than mc.precision digits.

BigDecimal.xor(BigInteger val) method returns The integer part of this / divisor .

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("1000.12");
  BigDecimal bg2 = new BigDecimal("332.32");

  MathContext mc = new MathContext(2);

  BigDecimal bg3 = bg1.divideToIntegralValue(bg2, mc);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 19 กันยายน พ.ศ. 2557

java.math.BigDecimal.doubleValue()

Description Of BigDecimal: doubleValue()

The java.math.BigDecimal.doubleValue() converts this BigDecimal to a double . This conversion is similar to the narrowing primitive conversion from double to float as defined in section 5.1.3 of The Java? Language Specification : if this BigDecimal has too great a magnitude represent as a double , it will be converted to Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY as appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of the BigDecimal value.

BigDecimal.doubleValue() method returns this BigDecimal converted to a double

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  double bg3 = bg1.doubleValue();
  double bg4 = bg2.doubleValue();

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


yengo หรือ buzzcity

วันพฤหัสบดีที่ 18 กันยายน พ.ศ. 2557

Java java.math BigDecimal equals(Object x)

Description Of BigDecimal: equals(Object x)

The java.math.BigDecimal.equals(Object x) compares this BigDecimal with the specified Object for equality. Unlike compareTo , this method considers two BigDecimal objects equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method).

BigDecimal.equals(Object x) method returns true if and only if the specified Object is a BigDecimal whose value and scale are equal to this BigDecimal 's.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 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);
  System.out.println(b2);
 }
}


yengo หรือ buzzcity

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 java.math BigDecimal floatValue()

Description Of BigDecimal: floatValue()

The java.math.BigDecimal.floatValue() converts this BigDecimal to a float . This conversion is similar to the narrowing primitive conversion from double to float as defined in section 5.1.3 of The Java? Language Specification : if this BigDecimal has too great a magnitude to represent as a float , it will be converted to Float.NEGATIVE_INFINITY or Float.POSITIVE_INFINITY as appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of the BigDecimal value.

BigDecimal.floatValue() method returns this BigDecimal converted to a float.

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  float b1 = bg1.floatValue();
  float b2 = bg2.floatValue();
  float b3 = bg3.floatValue();

  System.out.println(b1);
  System.out.println(b2);
  System.out.println(b3);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 16 กันยายน พ.ศ. 2557

Java java.math BigDecimal hashCode()

Description Of BigDecimal: hashCode()

The java.math.BigDecimal.hashCode() returns the hash code for this BigDecimal . Note that two BigDecimal objects that are numerically equal but differ in scale (like 2.0 and 2.00) will generally not have the same hash code.

BigDecimal.hashCode() method returns hash code for this BigDecimal

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  int b1 = bg1.hashCode();
  int b2 = bg2.hashCode();
  int b3 = bg3.hashCode();

  System.out.println(b1);
  System.out.println(b2);
  System.out.println(b3);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 15 กันยายน พ.ศ. 2557

Java java.math BigDecimal intValue()

Description Of BigDecimal: intValue()

The java.math.BigDecimal.intValue() converts this BigDecimal to an int . This conversion is analogous to the narrowing primitive conversion from double to short as defined in section 5.1.3 of The Java? Language Specification : any fractional part of this BigDecimal will be discarded, and if the resulting "BigInteger" is too big to fit in an int , only the low-order 32 bits are returned. Note that this conversion can lose information about the overall magnitude and precision of this BigDecimal value as well as return a result with the opposite sign.

BigDecimal.intValue() method returns this BigDecimal converted to an int .

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75.00");
  BigDecimal bg2 = new BigDecimal("25.60");
  BigDecimal bg3 = new BigDecimal("25");

  int b1 = bg1.intValue();
  int b2 = bg2.intValue();
  int b3 = bg3.intValue();

  System.out.println(b1);
  System.out.println(b2);
  System.out.println(b3);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 14 กันยายน พ.ศ. 2557

Java java.math BigDecimal intValueExact()

Description Of BigDecimal: intValueExact()

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

BigDecimal.intValueExact() method returns this BigDecimal converted to an int .

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75");
  BigDecimal bg2 = new BigDecimal("25");
  BigDecimal bg3 = new BigDecimal("25");

  int b1 = bg1.intValueExact();
  int b2 = bg2.intValueExact();
  int b3 = bg3.intValueExact();

  System.out.println(b1);
  System.out.println(b2);
  System.out.println(b3);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 13 กันยายน พ.ศ. 2557

Java java.math BigDecimal longValue()

Description Of BigDecimal: longValue()

The java.math.BigDecimal.longValue() converts this BigDecimal to a long . This conversion is analogous to the narrowing primitive conversion from double to short as defined in section 5.1.3 of The Java? Language Specification : any fractional part of this BigDecimal will be discarded, and if the resulting " BigInteger " is too big to fit in a long , only the low-order 64 bits are returned. Note that this conversion can lose information about the overall magnitude and precision of this BigDecimal value as well as return a result with the opposite sign.

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

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75.00");
  BigDecimal bg2 = new BigDecimal("25.50");
  BigDecimal bg3 = new BigDecimal("25");

  long b1 = bg1.longValue();
  long b2 = bg2.longValue();
  long b3 = bg3.longValue();

  System.out.println(b1);
  System.out.println(b2);
  System.out.println(b3);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 12 กันยายน พ.ศ. 2557

Java java.math BigDecimal longValueExact()

Description Of BigDecimal: longValueExact()

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

BigDecimal.longValueExact() method returns this BigDecimal converted to a long .

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("-75");
  BigDecimal bg2 = new BigDecimal("25");
  BigDecimal bg3 = new BigDecimal("25");

  long b1 = bg1.longValueExact();
  long b2 = bg2.longValueExact();
  long b3 = bg3.longValueExact();

  System.out.println(b1);
  System.out.println(b2);
  System.out.println(b3);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 11 กันยายน พ.ศ. 2557

Java java.math BigDecimal max(BigDecimal val)

Description Of BigDecimal: max(BigDecimal val)

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

BigDecimal.max(BigDecimal val) method returns the BigDecimal whose value is the greater of this BigDecimal and val . If they are equal, as defined by the compareTo method, this is returned.

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  BigDecimal bg3 = bg1.max(bg2);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันพุธที่ 10 กันยายน พ.ศ. 2557

Java java.math BigDecimal min(BigDecimal val)

Description Of BigDecimal: min(BigDecimal val)

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

BigDecimal.min(BigDecimal val) method returns the BigDecimal whose value is the lesser of this BigDecimal and val . If they are equal, as defined by the compareTo method, this is returned.

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  BigDecimal bg3 = bg1.min(bg2);

  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 9 กันยายน พ.ศ. 2557

Java java.math BigDecimal movePointLeft(int n)

Description Of BigDecimal: movePointLeft(int n)

The java.math.BigDecimal.movePointLeft(int n) returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the left. If n is non-negative, the call merely adds n to the scale. If n is negative, the call is equivalent to movePointRight(-n) . The BigDecimal returned by this call has value (this ? 10-n ) and scale max(this.scale()+n, 0) .

BigDecimal.movePointLeft(int n) method returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the left.

Code Example Java BigDecimal

import java.math.BigDecimal;

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

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

  // print bg3, bg4 values
  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 8 กันยายน พ.ศ. 2557

Java java.math BigDecimal movePointRight(int n)

Description Of BigDecimal: movePointRight(int n)

The java.math.BigDecimal.movePointRight(int n) returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the right. If n is non-negative, the call merely subtracts n from the scale. If n is negative, the call is equivalent to movePointLeft(-n) . The BigDecimal returned by this call has value (this ? 10n ) and scale max(this.scale()-n, 0) .

BigDecimal.movePointRight(int n) method returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the right.

Code Example Java BigDecimal

import java.math.BigDecimal;

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

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

  // print bg3, bg4 values
  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 7 กันยายน พ.ศ. 2557

Java java.math BigDecimal multiply(BigDecimal multiplicand)

Description Of BigDecimal: multiply(BigDecimal multiplicand)

The java.math.BigDecimal.multiply(BigDecimal multiplicand) returns a BigDecimal whose value is (this ? multiplicand) , and whose scale is (this.scale() + multiplicand.scale()).

BigDecimal.multiply(BigDecimal multiplicand) method returns this * multiplicand

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  BigDecimal bg3 = bg1.multiply(bg2);

  // print bg3 values
  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 6 กันยายน พ.ศ. 2557

Java java.math BigDecimal multiply(BigDecimal multiplicand, MathContext mc)

Description Of BigDecimal: multiply(BigDecimal multiplicand, MathContext mc)

The java.math.BigDecimal.multiply(BigDecimal multiplicand, MathContext mc) returns a BigDecimal whose value is (this ? multiplicand) , with rounding according to the context settings.

BigDecimal.multiply(BigDecimal multiplicand, MathContext mc) method returns this * multiplicand , 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("-75.3");
  BigDecimal bg2 = new BigDecimal("25.2");

  MathContext mc = new MathContext(4); // 4 precision
  
  BigDecimal bg3 = bg1.multiply(bg2, mc);

  // print bg3 values
  System.out.println(bg3);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 5 กันยายน พ.ศ. 2557

Java java.math BigDecimal negate()

Description Of BigDecimal: negate()

The java.math.BigDecimal.negate() returns a BigDecimal whose value is (-this) , and whose scale is this.scale().

BigDecimal.negate() method returns -this.

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  BigDecimal bg3 = bg1.negate();
  BigDecimal bg4 = bg2.negate();

  // print bg3, bg4 values
  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 4 กันยายน พ.ศ. 2557

Java java.math BigDecimal negate(MathContext mc)

Description Of BigDecimal: negate(MathContext mc)

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

BigDecimal.negate(MathContext mc) method returns -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) {
  BigDecimal bg1 = new BigDecimal("-75.312");
  BigDecimal bg2 = new BigDecimal("25.24212");

  MathContext mc = new MathContext(4);// 4 precision
  
  BigDecimal bg3 = bg1.negate(mc);
  BigDecimal bg4 = bg2.negate(mc);

  // print bg3, bg4 values
  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันพุธที่ 3 กันยายน พ.ศ. 2557

ตัวอย่างโค้ดภาษา Java การ Copy ข้อมูล ไปที่ clipboard

ตัวอย่างโค้ดภาษา Java การ Copy ข้อมูล ไปที่ clipboard


ตัวอย่างโค้ด Java ตัวอย่างนี้ เรามาดูวิธีการก็อบปี้ข้อความไปไว้ที่คลิปบอร์ดกันครับ ซึ่งอาจจะมีโปรแกรมที่ต้องการให้กดปุ่ม Copy แล้วคัดลอกข้อความที่ต้องการ เพื่อนำไปวางในที่ต่าง ๆ ได้

ตัวอย่างโค้ด

import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;

public class CodeFromDoesystem {
 public static void main(String[] args) throws Exception {
  copyToSystemClipboard("Test Copy To Clipboard");
 }

 public static void copyToSystemClipboard(String str) {
  StringSelection ss = new StringSelection(str);
  Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
 }
}

ตัวอย่างโค้ดตัวอย่างนี้ เราได้ทำการสร้าง method ที่ชื่อว่า copyToSystemClipboard สำหรับให้ระบบทำการ Copy ข้อความไปไว้ใน clipboard แล้วรับพารามิเตอร์เป็น String ที่ต้องการ

yengo หรือ buzzcity

Java java.math BigDecimal plus()

Description Of BigDecimal: plus()

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

BigDecimal.plus() method returns this

Code Example Java BigDecimal

import java.math.BigInteger;

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

  BigInteger bi3 = bi1.plus();
  BigInteger bi4 = bi2.plus();

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


yengo หรือ buzzcity

วันอังคารที่ 2 กันยายน พ.ศ. 2557

Java java.math BigDecimal plus(MathContext mc)

Description Of BigDecimal: plus(MathContext mc)

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

BigDecimal.plus(MathContext mc) method returns this , rounded as necessary. A zero result will have a scale of 0.

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("-75.312");
  BigDecimal bg2 = new BigDecimal("25.24212");

  MathContext mc = new MathContext(4);// 4 precision
  
  BigDecimal bg3 = bg1.plus(mc);
  BigDecimal bg4 = bg2.plus(mc);

  // print bg3, bg4 values
  System.out.println(bg3);
  System.out.println(bg4);
 }
}


yengo หรือ buzzcity

วันจันทร์ที่ 1 กันยายน พ.ศ. 2557

Java java.math BigDecimal pow(int n)

Description Of BigDecimal: pow(int n)

The java.math.BigDecimal.pow(int n) returns a BigDecimal whose value is (thisn ) , The power is computed exactly, to unlimited precision.

The parameter n must be in the range 0 through 999999999, inclusive. ZERO.pow(0) returns ONE . Note that future releases may expand the allowable exponent range of this method.

BigDecimal.pow(int n) method returns thisn

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  BigDecimal bg2 = bg1.pow(2);

  System.out.println(bg2);
 }
}


yengo หรือ buzzcity