Class AccurateFormatter


  • public class AccurateFormatter
    extends Object
    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
    • Field Detail

      • STANDARDIZED_LOCALE

        public static final Locale STANDARDIZED_LOCALE
        Standardized locale to use, to ensure files can be exchanged without internationalization issues.
    • Method Detail

      • format

        public static String format​(double value)
        Format a double number.
        Parameters:
        value - number to format
        Returns:
        number formatted to full accuracy
      • format

        public static String format​(int year,
                                    int month,
                                    int day,
                                    int hour,
                                    int minute,
                                    double seconds)
        Format a date.
        Parameters:
        year - year
        month - month
        day - day
        hour - hour
        minute - minute
        seconds - seconds
        Returns:
        date formatted to full accuracy