How to convert BigDecimal to Integer in Java

2 Answers

0 votes
import java.math.BigDecimal;

public class ConvertBigDecimalToInteger_Java {
    public static void main(String[] args) {
        BigDecimal bd = new BigDecimal("793298.12345");
        
        Integer i = bd.intValue(); 
        
        System.out.println(i);
    }
}
      
      
/*
run:
   
793298
       
*/

 



answered Sep 19, 2024 by avibootz
0 votes
import java.math.BigDecimal;

public class ConvertBigDecimalToInteger_Java {
    public static void main(String[] args) {
        BigDecimal bd = new BigDecimal("793298.12345");
        
        Integer i = bd.toBigInteger().intValueExact();
        
        System.out.println(i);
    }
}
      
      
/*
run:
   
793298
       
*/

 



answered Sep 19, 2024 by avibootz

Related questions

1 answer 125 views
1 answer 196 views
1 answer 122 views
1 answer 110 views
1 answer 93 views
93 views asked Jun 3, 2024 by avibootz
1 answer 128 views
128 views asked Jul 24, 2022 by avibootz
1 answer 206 views
...