Class EngineeringFormatter

java.lang.Object
org.djunits.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) 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:
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 - 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 - the value to format
      Returns:
      the formatted value
    • format

      public static String format(double val, int room)
      Format a double in Engineering format.
      Parameters:
      val - the value to format
      room - the width in characters of the result (minimum value is 10; values below this limit will be treated as 10)
      Returns:
      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 representation of a floating point value
      Returns:
      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 - input string
      width - length of the result
      Returns:
      the extended or trimmed input string