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