Package org.djunits.value.formatter
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-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.
- Version:
- $Revision: 873 $, $LastChangedDate: 2020-01-19 13:44:52 +0100 (Sun, 19 Jan 2020) $, by $Author: averbraeck $,
initial version 11 sep. 2015
- Author:
- Peter Knoppers
-
Method Summary
Modifier and Type Method Description static StringconvertToEngineering(String in)Make the exponent of a floating point value a multiple of 3.static Stringformat(double val)Format a double in Engineering format usingDEFAULTSIZEroom.static Stringformat(double val, int room)Format a double in Engineering format.static Stringpadd(String in, int width)Extend a String with spaces, or trim it to reach a specified length.static voidsetUpperCaseFormat(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 usingDEFAULTSIZEroom.- 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
-