Round a BigDecimal(double) down
import java.math.BigDecimal;
public class Main {
public static void main(String[] argv) throws Exception {
int decimalPlaces = 2;
BigDecimal bd = new BigDecimal("123456789.0123456890");
bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_DOWN);
String string = bd.toString();
System.out.println(string);
}
}
Output:
123456789.01
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