|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Object | +--Format
Formatting utilities.
| Constructor Summary | |
Format()
|
|
| Method Summary | |
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).
|
| 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 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.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||