Setting the Decimal Place of a Big Decimal Value - Java Language Basics

Java examples for Language Basics:BigDecimal

Description

Setting the Decimal Place of a Big Decimal Value

Demo Code

import java.math.BigDecimal;

public class Main {
  public static void main(String[] args) {
    int decimalPlaces = 2;
    BigDecimal bd = new BigDecimal("123");
    // Truncates the big decimal value.
    bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_DOWN);
    String string = bd.toString();
    System.out.println(string);//w  w w  .  j  a v a2s . co m
  }
}

Result


Related Tutorials