Java provides alot of powerful message formatting utilities which are not tied to I/O streams. These provide all sorts of mechanisms to allow you to format messages according to the local language and country-specific conventions. Check out the Javadoc and Sun's tutorials.
Object[] arguments = { name, formattedNumber, new Double(years), now, }; String message = "{0} earned ${1} after {2,number,integer} years as of {3,date}";
Comments
: cout.setf(ios::adjustfield);
:
Java provides alot of powerful message formatting utilities which are not tied to I/O streams. These provide all sorts of mechanisms to allow you to format messages according to the local language and country-specific conventions. Check out the Javadoc and Sun's tutorials.
Example:
[code]
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.Date;
public class FormatOutput {
public static void main(String[] args) {
double earnings = 126389471024.78826538;
double years = 12.3;
Date now = new Date();
String name = "John";
NumberFormat numberFormatter = new DecimalFormat("###,###.##");
String formattedNumber = numberFormatter.format(earnings);
Object[] arguments = { name, formattedNumber, new Double(years), now, };
String message =
"{0} earned ${1} after {2,number,integer} years as of {3,date}";
String outputString = MessageFormat.format(message, arguments);
System.out.println(outputString);
}
}
[/code]
(not that the above is best practice)
---------------------------------
[size=1](Its just my sig)
HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]