BigDecimal: setScale(int newScale, int roundingMode) : BigDecimal « java.math « Java by API






BigDecimal: setScale(int newScale, int roundingMode)

  
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);
  }

}
//3.14

   
    
  








Related examples in the same category

1.BigDecimal.ROUND_DOWN
2.BigDecimal.ROUND_HALF_DOWN
3.BigDecimal.ROUND_HALF_UP
4.BigDecimal.ROUND_UP
5.new BigDecimal(String val)
6.BigDecimal: abs()
7.BigDecimal: add(BigDecimal augend)
8.BigDecimal: doubleValue()
9.BigDecimal: divide(BigDecimal divisor)
10.BigDecimal: divide(BigDecimal divisor, int roundingMode)
11.BigDecimal: equals(Object x)
12.BigDecimal: max(BigDecimal val)
13.BigDecimal: min(BigDecimal val)
14.BigDecimal: multiply(BigDecimal multiplicand)
15.BigDecimal: negate()
16.BigDecimal: pow(int n)
17.BigDecimal: remainder(BigDecimal divisor)
18.BigDecimal: subtract(BigDecimal subtrahend)
19.BigDecimal: valueOf(long val)