Java Data Type Tutorial - Java BigDecimal .scaleByPowerOfTen (int n)








Syntax

BigDecimal.scaleByPowerOfTen(int n) has the following syntax.

public BigDecimal scaleByPowerOfTen(int n)

Example

In the following code shows how to use BigDecimal.scaleByPowerOfTen(int n) method.

/*from  w  w  w . ja  va 2 s .co m*/
import java.math.BigDecimal;

public class Main {

  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);
  }
}

The code above generates the following result.