Java BigDecimal.setScale(int newScale)

Syntax

BigDecimal.setScale(int newScale) has the following syntax.

public BigDecimal setScale(int newScale)

Example

In the following code shows how to use BigDecimal.setScale(int newScale) method.


//from  w  ww  .jav  a  2 s. co  m
import java.math.BigDecimal;

public class Main {

  public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("123.123456");

    // set scale of bg1 to 6 in bg2
    BigDecimal bg2 = bg1.setScale(6);

    String str = "The value of " + bg1 + " after changing the scale to 6 is "
        + bg2;

    System.out.println(str);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.math »




BigDecimal
BigInteger