Class Format
- java.lang.Object
-
- org.hortonmachine.gears.io.grasslegacy.utils.Format
-
public class Format extends Object
Fast, simple, and yet useful formattings.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static doubleatof(String s)Converts a string of digits to an doublestatic intatoi(String s)Converts a string of digits (decimal, octal or hex) to an integerstatic longatol(String s)Converts a string of digits (decimal, octal or hex) to a long integerstatic Stringconvert(long x, int n, String d)Converts number to stringStringform(char c)Formats a character into a string (like sprintf in C)Stringform(double x)Formats a double into a string (like sprintf in C)Stringform(int x)Formats an integer into a string (like sprintf in C)Stringform(long x)Formats a long integer into a string (like sprintf in C)Stringform(Character c)Stringform(Double x)Stringform(Float x)Stringform(Integer x)Stringform(Long x)Stringform(String s)Formats a string into a larger string (like sprintf in C)static Stringsprintf(String fmt, char x)prints a formatted number following printf conventionsstatic Stringsprintf(String fmt, double x)prints a formatted number following printf conventionsstatic Stringsprintf(String fmt, int x)prints a formatted number following printf conventionsstatic Stringsprintf(String s, int[] params)static Stringsprintf(String fmt, long x)prints a formatted number following printf conventionsstatic Stringsprintf(String fmt, Character x)static Stringsprintf(String s, Character[] params)static Stringsprintf(String fmt, Double x)static Stringsprintf(String s, Double[] params)static Stringsprintf(String fmt, Float x)static Stringsprintf(String s, Float[] params)static Stringsprintf(String fmt, Integer x)static Stringsprintf(String s, Integer[] params)static Stringsprintf(String fmt, Long x)static Stringsprintf(String s, Long[] params)static Stringsprintf(String s, Object[] params)Sprintf multiple strings.static Stringsprintf(String fmt, String x)prints a formatted number following printf conventionsstatic Stringsprintf(String s, String[] params)
-
-
-
Constructor Detail
-
Format
public Format(String s)
Formats a number in a printf format, like C- Parameters:
s- the format string following printf format string The string has a prefix, a format code and a suffix. The prefix and suffix become part of the formatted output. The format code directs the formatting of the (single) parameter to be formatted. The code has the following structure- a % (required)
- a modifier (optional)
- +
- forces display of + for positive numbers
- ~
- do not count leading + or - in length
- 0
- show leading zeroes
- -
- align left in the field
- space
- prepend a space in front of positive numbers
- #
- use "alternate" format. Add 0 or 0x for octal or hexadecimal numbers. Don't suppress trailing zeroes in general floating point format.
- an integer denoting field width (optional)
- a period followed by an integer denoting precision (optional)
- a format descriptor (required)
- f
- floating point number in fixed format
- e, E
- floating point number in exponential notation (scientific format). The E format results in an uppercase E for the exponent (1.14130E+003), the e format in a lowercase e.
- g, G
- floating point number in general format (fixed format for small numbers, exponential format for large numbers). Trailing zeroes are suppressed. The G format results in an uppercase E for the exponent (if any), the g format in a lowercase e.
- d, i
- signed long integer and integer in decimal
- u
- unsigned integer in decimal
- x
- unsigned integer in hexadecimal
- o
- unsigned integer in octal
- s
- string
- c
- character
-
-
Method Detail
-
form
public String form(char c)
Formats a character into a string (like sprintf in C)- Parameters:
c- the value to format- Returns:
- the formatted string
-
form
public String form(double x)
Formats a double into a string (like sprintf in C)- Parameters:
x- the number to format- Returns:
- the formatted string
-
form
public String form(long x)
Formats a long integer into a string (like sprintf in C)- Parameters:
x- the number to format- Returns:
- the formatted string
-
form
public String form(int x)
Formats an integer into a string (like sprintf in C)- Parameters:
x- the number to format- Returns:
- the formatted string
-
form
public String form(String s)
Formats a string into a larger string (like sprintf in C)- Parameters:
s- the value to format- Returns:
- the formatted string
-
atof
public static double atof(String s)
Converts a string of digits to an double- Parameters:
s- a string- Returns:
- double converted from String
-
atoi
public static int atoi(String s)
Converts a string of digits (decimal, octal or hex) to an integer- Parameters:
s- a string- Returns:
- the numeric value of the prefix of s representing a base 10 integer
-
atol
public static long atol(String s)
Converts a string of digits (decimal, octal or hex) to a long integer- Parameters:
s- a string- Returns:
- the numeric value of the prefix of s representing a base 10 integer
-
convert
public static String convert(long x, int n, String d)
Converts number to string- Parameters:
x- value to convertn- conversion based- string with characters for conversion.- Returns:
- converted number as string
-
sprintf
public static String sprintf(String fmt, char x)
prints a formatted number following printf conventions- Parameters:
fmt- the format stringx- the character to- Returns:
- formated string
-
sprintf
public static String sprintf(String fmt, double x)
prints a formatted number following printf conventions- Parameters:
fmt- the format stringx- the double to print- Returns:
- formated string
-
sprintf
public static String sprintf(String fmt, long x)
prints a formatted number following printf conventions- Parameters:
fmt- the format stringx- the long to print- Returns:
- formated string
-
sprintf
public static String sprintf(String fmt, int x)
prints a formatted number following printf conventions- Parameters:
fmt- the format stringx- the int to print- Returns:
- formated string
-
sprintf
public static String sprintf(String fmt, String x)
prints a formatted number following printf conventions- Parameters:
fmt-x- a string that represents the digits to print
-
sprintf
public static String sprintf(String s, Object[] params)
Sprintf multiple strings.- Parameters:
s-params-- Returns:
- formated string
-
-