BigDecimal.setScale(int newScale) has the following syntax.
public BigDecimal setScale(int newScale)
In the following code shows how to use BigDecimal.setScale(int newScale) method.
/* w w w .ja va 2s .c o 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.