Package org.djunits.value.formatter
Class EngineeringFormatter
java.lang.Object
org.djunits.value.formatter.EngineeringFormatter
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 Summary
Modifier and TypeMethodDescriptionstatic String
Make the exponent of a floating point value a multiple of 3.static String
format
(double val) Format a double in Engineering format usingDEFAULTSIZE
room.static String
format
(double val, int room) Format a double in Engineering format.static String
Extend a String with spaces, or trim it to reach a specified length.static void
setUpperCaseFormat
(boolean upper) Switch to/from upper case E for exponent indicator.
-
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
Format a double in Engineering format usingDEFAULTSIZE
room.- Parameters:
val
- double; the value to format- Returns:
- String; the formatted value
-
format
Format a double in Engineering format.- Parameters:
val
- double; the value to formatroom
- 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
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
Extend a String with spaces, or trim it to reach a specified length.- Parameters:
in
- String; input stringwidth
- int; length of the result- Returns:
- String; the extended or trimmed input string
-