Class Format


  • public class Format
    extends Object
    Fast, simple, and yet useful formattings.
    • 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 convert
        n - conversion base
        d - 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 string
        x - 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 string
        x - 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 string
        x - 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 string
        x - 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
      • sprintf

        public static String sprintf​(String s,
                                     int[] params)