Class Formatter

java.lang.Object
org.djunits.formatter.Formatter

public final class Formatter extends Object
Formatter of values with width and precision.

Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.

Author:
Alexander Verbraeck, Peter Knoppers
  • Field Details

    • DEFAULTPRECISION

      public static final int DEFAULTPRECISION
      Default number of fraction digits.
      See Also:
  • Method Details

    • formatString

      static String formatString(int width, int precision, String converter)
      Build a format string.
      Parameters:
      width - the number of characters in the result
      precision - the number of fractional digits in the result
      converter - the format conversion specifier
      Returns:
      suitable for formatting a float or double
    • format

      public static String format(double value, int width, int precision)
      Format a floating point value.
      Parameters:
      value - the value to format
      width - the number of characters in the result
      precision - the number of fractional digits in the result
      Returns:
      the formatted floating point value
    • format

      public static String format(double value, int width)
      Format a floating point value.
      Parameters:
      value - the value to format
      width - the number of characters in the result
      Returns:
      the formatted floating point value
    • format

      public static String format(double value)
      Format a floating point value.
      Parameters:
      value - the value to format
      Returns:
      the formatted floating point value