import java.text.MessageFormat; public class NombreVirgule { public static void main(String[] argv) throws Exception { Object[] params = new Object[] { new Double(3.14), new Double(1234.56) }; String msg = MessageFormat.format(" de {0,number,#.#} � {1,number,#.#}", params); System.out.println(msg); } } /* * Affichage: * de 3,1 � 1234,6 * */
A voir sur le même Sujet
-
Classe ‘MessageFormat’: Formater un Message qui contient un Nombre
{filelink=5924} import java.text.MessageFormat; public class ExempleMsgFormat2 { public static void main(String[] argv) throws Exception { Object[] params = new Object[] { new Integer(1939), new Integer(1945) …
-
MessageFormat: Formater un message
{filelink=5925} import java.text.MessageFormat; public class ExempleFomat { public static void main(String[] argv) throws Exception { Object[] params = new Object[] { “Fred”, “Jhon”, “Peter” }; …
-
Classe ‘Formatter’: Limiter le nombre de chiffre après la virgule
{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: …
-
Les nombre à virgule: Exemple de formatage d’un nombre négatif avec ‘printf’
{filelink=6043} public class FormatageN�gatif{ public static void main(String args[]) { System.out.printf(“Formatage nombre n�gatif: %,f”, -1234567.123); } } //Formatage nombre n�gatif: -1,234,567.123000
-
Classe ‘MessageFormat’: Exemple de Format pourcentage
{filelink=5929} import java.text.MessageFormat; public class FormatPoucentage { public static void main(String[] argv) throws Exception { Object[] data = new Object[] { new Double(123.45), new Double(123.56) …
-
Classe ‘MessageFormat’: Exemple de Format monétaire
{filelink=5928} import java.text.MessageFormat; public class FormatMonnaie { public static void main(String[] argv) throws Exception { Object[] data = new Object[] { new Double(250.50), new Double(650.15) …
-
Arrondir un nombre décimal de type ‘BigDecimal’
{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 …
-
Classe ‘MessageFormat’: Comment combiner la date avec des phrases
{filelink=5937} import java.text.MessageFormat; import java.util.Date; public class AffichageMois { public static void main(String[] argv) throws Exception { Object[] params = new Object[] { new Date()}; …
-
Comment spécifier le nombre de chiffre après la virgule, le nombre caractère etc
{filelink=4422} import java.util.Formatter; public class MainClass { public static void main(String args[]) { Formatter fmt = new Formatter(); fmt.format(“%.4f”, 250.2352); System.out.println(fmt); fmt = new Formatter(); …
-
Classe ‘MessageFormat’: Utiliser un format personnalisé pour l’heure et la Date
{filelink=5935} import java.text.MessageFormat; import java.util.Date; public class HeureFormatPersonnel { public static void main(String[] argv) throws Exception { Object[] data = new Object[] { new Date(), …