import java.text.MessageFormat; public class FormatagePersonnel { public static void main(String[] argv) throws Exception { Object[] params = new Object[] { new Integer(128), new Integer(255) }; String msg = MessageFormat.format("{0,number,#} a''s and {1,number,#} b''s", params); System.out.println(msg); } } /* * Affichage: * 123 a's and 1234 b's * **/
A voir sur le même Sujet
-
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 remplacement des ‘token’ dans une chaîne de caractère
{filelink=5923} import java.text.MessageFormat; public class ExempleMsgFormat { public static void main(String[] argv) { Object[] params = new Object[] { “Bienvenu”, “Paris”, “Berne”, “Londre” }; System.out.println(MessageFormat.format(“{0} …
-
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) …
-
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()}; …
-
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 ‘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(), …
-
Classe ‘MessageFormat’: Afficher l’heure en format long (Exemple: 16:07:33 GMT)
{filelink=5933} import java.text.MessageFormat; import java.util.Date; public class HeureFormatLong { public static void main(String[] argv) throws Exception { Object[] params = new Object[] { new Date(), …
-
MessageFormat: Formater un nombre à virgule
{filelink=5927} 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) …