CSLib
Class SFormat


public class SFormat

SFormat is a utility class for formatting numbers as
strings. It has methods for formatting ints and
doubles, justified in various ways.

Author:
M. Dennis Mickunas

Method Summary
 static Stringsprint(int r, double d)
          Stringifies a decimal with r decimal places to the right
of the point, in a field fitted to the number.
 static Stringsprint(double d)
          Stringifies a decimal with 2 decimal places to the right of
the point, in a field fitted to the number (as for currency).
 static Stringsprintc(int w, int i)
          Stringifies an integer centered in a field of width w.
 static Stringsprintc(int w, int r, double d)
          Stringifies a decimal with r decimal places to the right
of the point, centered in a field of width w.
 static Stringsprintc(int w, String str)
          Centers a string in a field of width w.
 static Stringsprintr(int w, int i)
          Stringifies an integer right-justified in a field of width w.
 static Stringsprintr(int w, String str)
          Right-justifies a String in a field of width w.
 static Stringsprintr(int w, int r, double d)
          Stringifies a decimal with r decimal places to the right of
the point, right-justified in a field of width w.
 static Stringsprintzr(int w, int i)
          Stringifies an integer in a field of width w,
right-justified and zero-filled.

Method Detail

sprint

public static String sprint(int r, double d)
Stringifies a decimal with r decimal places to the right
of the point, in a field fitted to the number.
Parameters:
r the number of places to the right of the decimal point.
d the double to stringify.
See Also:
sprintr(int,int,double)

sprint

public static String sprint(double d)
Stringifies a decimal with 2 decimal places to the right of
the point, in a field fitted to the number (as for currency).
Parameters:
d the double to stringify.
See Also:
sprint(int,double)

sprintc

public static String sprintc(int w, int i)
Stringifies an integer centered in a field of width w.
Parameters:
w the field width.
i the int to stringify.
See Also:
java.lang.String.length(), java.lang.String.substring(int,int)

sprintc

public static String sprintc(int w, int r, double d)
Stringifies a decimal with r decimal places to the right
of the point, centered in a field of width w.
Parameters:
w the field width.
r the number of places to the right of the decimal point.
d the double to stringify.
See Also:
sprint(int,double)

sprintc

public static String sprintc(int w, String str)
Centers a string in a field of width w.
Parameters:
w the field width.
str the String to center.
See Also:
java.lang.String.length(), java.lang.String.substring(int,int)

sprintr

public static String sprintr(int w, int i)
Stringifies an integer right-justified in a field of width w.
Parameters:
w the field width.
i the int to stringify.
See Also:
java.lang.Math.max(int,int), java.lang.String.substring(int), java.lang.String.length()

sprintr

public static String sprintr(int w, String str)
Right-justifies a String in a field of width w.
Parameters:
w the field width.
str the String to justify.
See Also:
java.lang.Math.max(int,int), java.lang.String.substring(int), java.lang.String.length()

sprintr

public static String sprintr(int w, int r, double d)
Stringifies a decimal with r decimal places to the right of
the point, right-justified in a field of width w.
Parameters:
w the field width.
r the number of places to the right of the decimal point.
d the double to stringify.
See Also:
java.lang.Math.round(double), java.lang.Math.pow(double,double), java.lang.Math.floor(double), sprintr(int,int), sprintzr(int,int)

sprintzr

public static String sprintzr(int w, int i)
Stringifies an integer in a field of width w,
right-justified and zero-filled.
Parameters:
w the field width.
i the int to stringify.
See Also:
java.lang.Math.max(int,int), java.lang.String.length(), java.lang.String.substring(int,int)

Association Links

to Class java.lang.String

to Class java.lang.String

to Class java.lang.String