|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavabook.Format
This class is used to format the numerical and textual values for a properly aligned output display.
This class is provided as freeware. You are free to use as provided or modify to your heart's content. But you use it at your own risk. No implied or explicit warranty is given.
Constructor Summary | |
Format()
|
Method Summary | |
static java.lang.String |
centerAlign(int width,
int decimalPlaces,
double number)
Formats a real number using the center alignment. |
static java.lang.String |
centerAlign(int width,
long number)
Formats an integer using the center alignment. |
static java.lang.String |
centerAlign(int width,
java.lang.String str)
Formats a String using the center alignment. |
static java.lang.String |
leftAlign(int width,
int decimalPlaces,
double number)
Formats a real number using the left alignment. |
static java.lang.String |
leftAlign(int width,
long number)
Formats an integer using the left alignment. |
static java.lang.String |
leftAlign(int width,
java.lang.String str)
Formats a String using the left alignment. |
static java.lang.String |
rightAlign(int width,
int decimalPlaces,
double number)
Formats a real number using the right alignment. |
static java.lang.String |
rightAlign(int width,
long number)
Formats an integer using the right alignment. |
static java.lang.String |
rightAlign(int width,
java.lang.String str)
Formats a String using the right alignment. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Format()
Method Detail |
public static java.lang.String centerAlign(int width, int decimalPlaces, double number)
number
is converted to a String
with width
characters. The number is placed at the center,
and the second parameter decimalPlaces
determines the
number of decimal places to be shown. If the converted number has
more characters than the designated width
, then
the converted number is returned without any formatting.
width
- number of characters the resulting string will containdecimalPlaces
- the number of decimal places within the designated
field widthnumber
- the value to be formatted
public static java.lang.String centerAlign(int width, long number)
number
is converted to a String
with width
characters. The number is placed at the center.
If the converted number has more characters than the designated width
, then
the converted number is returned without any formatting.
width
- the number of characters the resulting string will containnumber
- the integer value to be formatted
public static java.lang.String centerAlign(int width, java.lang.String str)
String
using the center alignment.
The passed str
is converted to a new String
with width
characters. The string str
is placed
at the center of the new string.
If the original str
has more characters than the designated width
, then
the original str
is returned without any formatting.
width
- the number of characters the resulting string will containstr
- the String
value to be formatted
public static java.lang.String leftAlign(int width, int decimalPlaces, double number)
number
is converted to a String
with width
characters. The number is placed at the left,
and the second parameter decimalPlaces
determines the
number of decimal places to be shown. If the converted number has
more characters than the designated width
, then
the converted number is returned without any formatting.
width
- number of characters the resulting string will containdecimalPlaces
- the number of decimal places within the designated
field widthnumber
- the value to be formatted
public static java.lang.String leftAlign(int width, long number)
number
is converted to a String
with width
characters. The number is placed at the left.
If the converted number has more characters than the designated width
, then
the converted number is returned without any formatting.
width
- the number of characters the resulting string will containnumber
- the integer value to be formatted
public static java.lang.String leftAlign(int width, java.lang.String str)
String
using the left alignment.
The passed str
is converted to a new String
with width
characters. The string str
is placed
at the left of the new string.
If the original str
has more characters than the designated width
, then
the original str
is returned without any formatting.
width
- the number of characters the resulting string will containstr
- the String
value to be formatted
public static java.lang.String rightAlign(int width, int decimalPlaces, double number)
number
is converted to a String
with width
characters. The number is placed at the right,
and the second parameter decimalPlaces
determines the
number of decimal places to be shown. If the converted number has
more characters than the designated width
, then
the converted number is returned without any formatting.
width
- number of characters the resulting string will containdecimalPlaces
- the number of decimal places within the designated
field widthnumber
- the value to be formatted
public static java.lang.String rightAlign(int width, long number)
number
is converted to a String
with width
characters. The number is placed at the right.
If the converted number has more characters than the designated width
, then
the converted number is returned without any formatting.
width
- the number of characters the resulting string will containnumber
- the integer value to be formatted
public static java.lang.String rightAlign(int width, java.lang.String str)
String
using the right alignment.
The passed str
is converted to a new String
with width
characters. The string str
is placed
at the right of the new string.
If the original str
has more characters than the designated width
, then
the original str
is returned without any formatting.
width
- the number of characters the resulting string will containstr
- the String
value to be formatted
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |