How to round BigDecimal to the nearest whole value in Java

1 Answer

0 votes
import java.math.BigDecimal;
 
public class Program {
    public static void main(String[] args) {
        BigDecimal bd = new BigDecimal("93298.5234");
        
        bd = bd.setScale(0, BigDecimal.ROUND_HALF_UP);
        
        System.out.println(bd);
    }
}
   
   
    
/*
run
    
93299
    
*/

 



answered Jun 4, 2024 by avibootz

Related questions

1 answer 122 views
1 answer 93 views
93 views asked Jun 3, 2024 by avibootz
1 answer 62 views
1 answer 115 views
1 answer 130 views
1 answer 157 views
...