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 242 views
1 answer 302 views
1 answer 222 views
1 answer 209 views
1 answer 180 views
180 views asked Jun 3, 2024 by avibootz
1 answer 226 views
226 views asked Jul 24, 2022 by avibootz
1 answer 320 views
...