Java BigDecimal intValue() Method with Example

BigDecimal Class intValue() method: Here, we are going to learn about the intValue() method of BigDecimal Class with its syntax and example.
Submitted by Preeti Jain, on May 04, 2020

BigDecimal Class intValue() method

  • intValue() method is available in java.math package.
  • intValue() method is used to convert a BigDecimal to an integer and when the converted BigDecimal value is large enough to fit into an integer then in that case low order 32 bits are to be retrieved and the returned value is with opposite sign.
  • intValue() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • intValue() method does not throw an exception at the time of converting BigDecimal to int.


    public int intValue();


  • It does not accept any parameter.

Return value:

The return type of this method is int, it gets the integer representation of this BigDecimal.


// Java program to demonstrate the example 
// of int intValue() method of BigDecimal

import java.math.*;

public class IntValueOfBD {
    public static void main(String args[]) {
        // Initialize two variables first is
        // of "double" and second is of "String"
        // type
        double val = 115.23;
        String str = "100";

        // Initialize two BigDecimal objects  
        BigDecimal b_dec1 = new BigDecimal(val);
        BigDecimal b_dec2 = new BigDecimal(str);

        // convert this BigDecimal (b_dec1) into
        // an int, variable named i_conv
        int i_conv = b_dec1.intValue();
        System.out.println("b_dec1.intValue(): " + i_conv);

        // convert this BigDecimal (b_dec2) into
        // an int, variable named i_conv
        i_conv = b_dec2.intValue();
        System.out.println("b_dec2.intValue(): " + i_conv);


b_dec1.intValue(): 115
b_dec2.intValue(): 100


Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.