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-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.
- Version:
- $Revision: 669 $, $LastChangedDate: 2019-10-18 14:27:35 +0200 (Fri, 18 Oct 2019) $, by $Author: averbraeck $,
initial version 11 sep. 2015
- Author:
- Peter Knoppers
-
Method Summary
Modifier and Type Method Description static String
convertToEngineering(String in)
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
padd(String in, int width)
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
-