วันอังคารที่ 26 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal scale()

Description Of BigDecimal: scale()

The java.math.BigDecimal.scale() returns the scale of this BigDecimal . If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. For example, a scale of -3 means the unscaled value is multiplied by 1000.

BigDecimal.scale() method returns the scale of this BigDecimal .

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  // assign the result of scale on bg1, bg2 to i1,i2
  int i1 = bg1.scale();
  int i2 = bg2.scale();

  String str1 = "The scale of " + bg1 + " is " + i1;
  String str2 = "The scale of " + bg2 + " is " + i2;

  // print the values of i1,i2;
  System.out.println(str1);
  System.out.println(str2);
 }
}


yengo หรือ buzzcity

ไม่มีความคิดเห็น :

แสดงความคิดเห็น