Class AccurateFormatter

  • All Implemented Interfaces:
    Formatter

    public class AccurateFormatter
    extends Object
    implements Formatter
    Formatter used to produce strings from data with high accuracy.

    When producing test output from computed data, we want the shortest decimal representation of a floating point number that maintains round-trip safety. That is, a correct parser can recover the exact original number.

    For efficiency, this class uses the Ryū algorithm for producing shortest string representation with round-trip safety.

    Since:
    11.0
    Author:
    Luc Maisonobe
    • Constructor Detail

      • AccurateFormatter

        public AccurateFormatter()
        Public constructor.
    • Method Detail

      • toString

        public String toString​(double value)
        Formats to full accuracy. Format a double number.
        Specified by:
        toString in interface Formatter
        Parameters:
        value - number to format
        Returns:
        number formatted.
      • toString

        public String toString​(int year,
                               int month,
                               int day,
                               int hour,
                               int minute,
                               double seconds)
        Formats the seconds variable with maximum precision needed. Format a date. Does not check if date time is real or if it will meet formating requirements.
        Specified by:
        toString in interface Formatter
        Parameters:
        year - of date to be formatted
        month - of date to be formatted
        day - of month to be formatted
        hour - to be formatted
        minute - to be formatted
        seconds - and sub-seconds to be formatted
        Returns:
        date formatted to match the following format [yyyy-MM-ddTHH:mm:ss.S#]
      • format

        @Deprecated
        public static String format​(int year,
                                    int month,
                                    int day,
                                    int hour,
                                    int minute,
                                    double seconds)
        Deprecated.
        As of 13.0, because static method does not utilize inheritance benefits from Formatter and does not check format standards of date time. Use toString(int, int, int, int, int, double) instead.
        Format a date.
        Parameters:
        year - year
        month - month
        day - day
        hour - hour
        minute - minute
        seconds - seconds
        Returns:
        date formatted to full accuracy
      • format

        @Deprecated
        public static String format​(double value)
        Deprecated.
        As of 13.0, because Static method does not utilize inheritance benefits from Formatter. Use toString(double) instead.
        Format a double number.
        Parameters:
        value - number to format
        Returns:
        number formatted to full accuracy