Class Formatter

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

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

Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.

Version:
$Revision: 324 $, $LastChangedDate: 2019-01-18 00:35:01 +0100 (Fri, 18 Jan 2019) $, by $Author: averbraeck $, initial version 11 sep. 2015
Author:
Alexander Verbraeck, Peter Knoppers
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int DEFAULTPRECISION
    Default number of fraction digits.
  • Method Summary

    Modifier and Type Method Description
    static String format​(double value, int size)
    Format a floating point value.
    static String format​(double value, int width, int precision)
    Format a floating point value.
    static String format​(float value)
    Format a floating point value.
    static String format​(float value, int size)
    Format a floating point value.
    static String format​(float value, int width, int precision)
    Format a floating point value.
    (package private) static String formatString​(int width, int precision, String converter)
    Build a format string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • formatString

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

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

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

      public static String format​(float value)
      Format a floating point value.
      Parameters:
      value - float; the value to format
      Returns:
      String; the formatted floating point value
    • format

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

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