Round a BigDecimal(double) up
import java.math.BigDecimal;
public class Main {
public static void main(String args[]) {
BigDecimal bd = new BigDecimal(3.14159);
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println(bd);
}
}
Output:
3.14
Home
Java Book
Runnable examples
Java Book
Runnable examples
BigDecimal:
- Create BigDecimal from long and String
- Add two BigDecimal together
- Divide BigDecimal from another BigDecimal
- Multiply one BigDecimal to another BigDecimal
- Negate a BigDecimal
- Subtract BigDecimal from another BigDecimal
- Truncate BigDecimal value
- Power a BigDecimal
- Round a BigDecimal(double) up
- Round a BigDecimal(double) down
- Format BigDecimal to Currency and Percentage