|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.cip4.jdflib.cformat.PrintfFormat
public class PrintfFormat
Object for formatting output in the same way as the C printf methodName.
A printf style format string is specified in the constructor. Once instantiated, the tostr methods of this class may be used to convert primitives types (float, double, char, int, long, String) into Strings. Alternatively, instances of this class may be passed as arguments to the printf methods of the PrintfWriter or PrintfStream classes.
Examples:
double theta1 = 45.0;
double theta2 = 85.0;
PrintfFormat fmt = new PrintfFormat("%7.2f\n");
System.out.println("theta1=" + fmt.tostr(theta1) + "theta2=" + fmt.tostr(theta2));
PrintfStream pfw = new PrintfStream(System.out, true);
pfw.print("theta1=");
pfw.printf(fmt, theta1);
pfw.print("theta2=");
pfw.printf(fmt, theta2);
PrintfWriter,
PrintfStream| Constructor Summary | |
|---|---|
PrintfFormat(String fmt)
Creates a new instance of PrintfFormat from the supplied format string. |
|
| Method Summary | |
|---|---|
String |
getPrefix()
Gets the prefix string associated with the format. |
String |
getSuffix()
Gets the suffix string associated with the format. |
void |
set(String fmt)
Sets the format characteristics according to the supplied String. |
String |
setPrefix(String s)
Sets the prefix string associated with the format. |
String |
setSuffix(String s)
Sets the suffix string associated with the format. |
String |
tostr(char x)
Formats a char into a string. |
String |
tostr(double x)
Formats a double into a string. |
String |
tostr(Double x)
Formats a Double into a string. |
String |
tostr(float x)
Formats a float into a string. |
String |
tostr(int x)
Formats an int into a string. |
String |
tostr(Integer x)
Formats an Integer into a string. |
String |
tostr(long x)
Formats a long into a string. |
String |
tostr(String x)
Formats a String into a string. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PrintfFormat(String fmt)
throws IllegalArgumentException
fmt - Format string
IllegalArgumentException - Malformed format stringset(java.lang.String)| Method Detail |
|---|
public String getPrefix()
setPrefix(java.lang.String)public String getSuffix()
setSuffix(java.lang.String)
public void set(String fmt)
throws IllegalArgumentException
The format string has the same form as the one used by the C printf methodName, except that only one conversion sequence may be specified (because routines which use PrintfFormat each convert only one object).
The format string consists of an optional prefix of regular characters, followed by a conversion sequence, followed by an optional suffix of regular characters.
The conversion sequence is introduced by a '%' character, and is followed by any number of optional flag characters, an optional unsigned decimal integer specifying a field width, another optional unsigned decimal integer (preceded by a '.' character) specifying a precision, and finally a conversion character. To incorporate a '%' character into either the prefix or suffix, one should specify the sequence "%%". The allowed flag characters are:
The conversion character is one of:
fmt - Format string
IllegalArgumentException - Malformed format stringpublic String setPrefix(String s)
s - New prefix stringgetPrefix()public String setSuffix(String s)
s - New suffix stringgetSuffix()public String tostr(float x)
x - Float value to convert
public String tostr(Double x)
x - Float value to convert
public String tostr(Integer x)
x - Float value to convert
public String tostr(double x)
x - Double value to convert
public String tostr(int x)
x - Int value to convert
public String tostr(long x)
x - Long value to convert
public String tostr(char x)
x - Char value to convert
public String tostr(String x)
x - String value to format
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||