Converting BigDecimal to an int

Question:
How to Convert a BigDecimal to an int?
Converting BigDecimal to Integer

Answer:
bigdecimal.intValue();

Code:
import java.math.*;
 
public class BigDecimalTest {
  public static void main(String[] args) {
 
    BigDecimal big = new BigDecimal(123.456);
    int x = big.intValue();
    System.out.println(x);
  }
}
 

Output:
$ java BigDecimalTest
123

How to multiply a BigDecimal by an integer in Java?

Question:
How to multiply a BigDecimal by an int in Java?
Multiplication with BigDecimals.

Answer:
bigdecimal.multiply(new BigDecimal(int))

Code:
import java.math.*;
 
public class BigDecimalTest {
  public static void main(String[] args) {
 
    BigDecimal bd = new BigDecimal(2.0);
    int x = 5;
    bd = bd.multiply(new BigDecimal(x));
    System.out.println(bd);
  }
}
 

Output:
$ java BigDecimalTest
10

How to test if a BigDecimal is less then zero?

Question:
How to test if a BigDecimal is less then zero?
How to compare BigDecimal to an int?

Answer:
number.compareTo(BigDecimal.ZERO)

Code:
import java.math.*;
 
public class BigDecimalTest {
  public static void main(String[] args) {
    BigDecimal bd = new BigDecimal(-1.5);
 
    if (bd.compareTo(BigDecimal.ZERO) < 0) {
      System.out.println(bd + " is less then zero");
    }
  }
}
 

Output:
$ java BigDecimalTest
-1.5 is less then zero