วันเสาร์ที่ 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