Friday, September 5, 2025
HomeLanguagesJavaBigDecimal scale() Method in Java

BigDecimal scale() Method in Java

The java.math.BigDecimal.scale() is an inbuilt method in java that returns the scale of this BigDecimal.

  • For zero or positive value, the scale is the number of digits to the right of the decimal point.
  • For negative value, the unscaled value of the number is multiplied by ten to the power of the negation of the scale.

Syntax:

public int scale()

Parameters: This method does not accepts any parameter.

Return value: This method returns the scale of this BigDecimal object.

Below program illustrates the working of the above mentioned method:

Program 1:




// Java program to demonstrate the
// scale() method
  
import java.math.*;
  
public class Gfg {
  
    public static void main(String[] args)
    {
  
        BigDecimal b1 = new BigDecimal("456.0");
        BigDecimal b2 = new BigDecimal("-1.456");
  
        // Assign the result of scale on
        // BigDecimal Objects b1, b2 to int objects i1, i2
        int i1 = b1.scale();
        int i2 = b2.scale();
  
        // Print the values of i1, i2;
        System.out.println("The scale of " + b1 + " is " + i1);
        System.out.println("The scale of " + b2 + " is " + i2);
    }
}


Output:

The scale of 456.0 is 1
The scale of -1.456 is 3

Program 2:




// Java program to demonstrate the
// scale() method
  
import java.math.*;
  
public class Gfg {
  
    public static void main(String[] args)
    {
  
        BigDecimal b1 = new BigDecimal("745");
        BigDecimal b2 = new BigDecimal("-174");
  
        // Assign the result of scale on
        // BigDecimal Objects b1, b2 to int objects i1, i2
        int i1 = b1.scale();
        int i2 = b2.scale();
  
        // Print the values of i1, i2;
        System.out.println("The scale of " + b1 + " is " + i1);
        System.out.println("The scale of " + b2 + " is " + i2);
    }
}


Output:

The scale of 745 is 0
The scale of -174 is 0

Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#scale()

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS