Truncate the big decimal value by rounding up in Java
Description
The following code shows how to truncate the big decimal value by rounding up.
Example
//from w ww . ja va 2s . c o m
import java.math.BigDecimal;
public class Main {
public static void main(String[] argv) throws Exception {
int decimalPlaces = 2;
BigDecimal bd = new BigDecimal("123456789.0123456890");
System.out.println(bd);
bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_UP);
System.out.println(bd);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »