Class EngineeringFormatter

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

public final class EngineeringFormatter extends Object
Format a value in Engineering notation, or normal floating point notation if that can represent the value more accurately.

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

Version:
$Revision: 954 $, $LastChangedDate: 2022-01-10 03:42:57 +0100 (Mon, 10 Jan 2022) $, by $Author: averbraeck $, initial version 11 sep. 2015
Author:
Peter Knoppers
  • Method Details

    • setUpperCaseFormat

      public static void setUpperCaseFormat(boolean upper)
      Switch to/from upper case E for exponent indicator. The default is to use upper case.
      Parameters:
      upper - boolean; if true; an upper case E will be used; if false; a lower case e will be used
    • format

      public static String format(double val)
      Format a double in Engineering format using DEFAULTSIZE room.
      Parameters:
      val - double; the value to format
      Returns:
      String; the formatted value
    • format

      public static String format(double val, int room)
      Format a double in Engineering format.
      Parameters:
      val - double; the value to format
      room - int; the width in characters of the result (minimum value is 10; values below this limit will be treated as 10)
      Returns:
      String; the formatted value
    • convertToEngineering

      public static String convertToEngineering(String in)
      Make the exponent of a floating point value a multiple of 3. Assumes that the first dot or comma is the radix symbol and 'e' or 'E' is used at the exponent symbol.
      Parameters:
      in - String; String representation of a floating point value
      Returns:
      String; The engineering formatted value
    • padd

      public static String padd(String in, int width)
      Extend a String with spaces, or trim it to reach a specified length.
      Parameters:
      in - String; input string
      width - int; length of the result
      Returns:
      String; the extended or trimmed input string