|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
ObjectFormat
Formatting utilities.
| Constructor Summary | |
Format()
|
|
| Method Summary | |
static String |
cardinal(int x)
cardinal(58) is "fifty-eight", for example. |
static String |
ordinal(int x)
ordinal(58) is "fifty-eighth", for example. |
static void |
pad(StringBuffer s,
int n)
Add spaces to s to make its length equal to
n. |
static String |
round(float x,
int dec_places)
Given the float x, rounds it off to the nearest
dec_places decimal places, if any. |
static String |
roundToSigFig(float x,
int sig_figs)
Converts the number of significant figures ( sig_figs) into the appropriate number of decimal
places, then passes off the work to round(float, int).
|
static void |
setTabStops(int[] value)
See tab(java.lang.StringBuffer). |
static void |
tab(StringBuffer s)
Finds the leftmost t in tabStops
that's greater than the length of s, and pads
s with spaces until its length is t.
|
| Methods inherited from class Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Format()
| Method Detail |
public static String cardinal(int x)
cardinal(58) is "fifty-eight", for example. It
would be cool to do this for type long or
BigInteger.
public static String ordinal(int x)
ordinal(58) is "fifty-eighth", for example. It
would be cool to do this for type long or
BigInteger.
public static String round(float x,
int dec_places)
x, rounds it off to the nearest
dec_places decimal places, if any. Examples:
Format.round(1.7320508, 3, true) returns 1.732
Format.round(1.7320508, 4, true) returns 1.7321
WARNING: there will be errors if rounding x *
10^(dec_places) to the nearest integer overflows the
int datatype.
IllegalArgumentException - If dec_places
is less than 0 (just because we haven't written that case).
public static String roundToSigFig(float x,
int sig_figs)
sig_figs) into the appropriate number of decimal
places, then passes off the work to round(float, int).
The result is incorrect in some ways.
x. For instance, roundToSigFig(1001,
3) is 1001.
sig_figs. For instance, roundToSigFig(.001,
3) is .001, not .00100. This is what you want, say,
when you're labeling the interval [0,1] on a chart.
public static void pad(StringBuffer s,
int n)
s to make its length equal to
n. If s is already of length ≥
n, add one space.
public static void setTabStops(int[] value)
tab(java.lang.StringBuffer).
public static void tab(StringBuffer s)
t in tabStops
that's greater than the length of s, and pads
s with spaces until its length is t.
If no entry in tabStops is big enough, adds one
space to s.
The user should reset tabStops using setTabStops(int[]) as desired.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||