Description Of BigDecimal: scaleByPowerOfTen(int n)
The java.math.BigDecimal.scaleByPowerOfTen(int n) returns a BigDecimal whose numerical value is equal to ( this * 10n ). The scale of the result is (this.scale() - n).BigDecimal.scaleByPowerOfTen(int n) method returns a BigDecimal whose numerical value is equal to ( this * 10n ). The scale of the result is (this.scale() - n).
Code Example Java BigDecimal
import java.math.BigDecimal;
public class BigDecimalExam {
public static void main(String[] args) {
BigDecimal bg1 = new BigDecimal("123.000");
BigDecimal bg2 = new BigDecimal("12300");
BigDecimal bg3 = bg1.scaleByPowerOfTen(3);
BigDecimal bg4 = bg2.scaleByPowerOfTen(-3);
String str1 = bg1 + " raised to 10 power 3 is " + bg3;
String str2 = bg2 + " raised to 10 power -3 is " + bg4;
System.out.println(str1);
System.out.println(str2);
}
}
ไม่มีความคิดเห็น :
แสดงความคิดเห็น