Classe ‘Formatter’: Limiter le nombre de chiffre après la virgule

Author:


{filelink=5764}


import java.util.Formatter;

public class FormatageSortie {
  public static void main(String[] argv) throws Exception {
    Formatter fmt = new Formatter();
    fmt.format("Aucune précision sur le décimal: %fn", 10.0 / 3.0);
    fmt.format("deux chiffres après la virgule: %.2f", 10.0 / 3.0);
    System.out.println(fmt);

  }
}

/**
 * Sortie
 * Aucune précision sur le décimal: 3,333333
 * deux chiffres après la virgule: 3,33
 *
 */

Leave a Reply

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