Arrondir un nombre décimal de type ‘BigDecimal’

Author:

 set, java
{filelink=11203}


import java.math.BigDecimal;

public class Arrondir
 {

  public static void main(String args[])
  	{

    BigDecimal pi = new BigDecimal(3.1415923);

    // Arrondir le nombre; retenir deux chiffres après la virgule
    pi = pi.setScale(2, BigDecimal.ROUND_HALF_UP);

    System.out.println(pi);
   }

}

Leave a Reply

Your email address will not be published. Required fields are marked *