Java BigDecimal.scale()

Syntax

BigDecimal.scale() has the following syntax.

public int scale()

Example

In the following code shows how to use BigDecimal.scale() method.


import java.math.BigDecimal;
//  ww w . j a  va2 s.  c  o m
public class Main {

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

The code above generates the following result.





















Home »
  Java Tutorial »
    java.math »




BigDecimal
BigInteger