Package org.openl.rules.util
Class Numbers
- java.lang.Object
-
- org.openl.rules.util.Numbers
-
public final class Numbers extends Object
A set of functions to work with numbers
-
-
Field Summary
Fields Modifier and Type Field Description static StringNEGATIVE_INFINITY_SIGNstatic StringPOSITIVE_INFINITY_SIGN
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringtoString(Number number)DefaulttoStringmethod for numbers.static StringtoString(Number number, String pattern)Formatting method for numbers.
-
-
-
Field Detail
-
POSITIVE_INFINITY_SIGN
public static final String POSITIVE_INFINITY_SIGN
- See Also:
- Constant Field Values
-
NEGATIVE_INFINITY_SIGN
public static final String NEGATIVE_INFINITY_SIGN
- See Also:
- Constant Field Values
-
-
Method Detail
-
toString
public static String toString(Number number)
DefaulttoStringmethod for numbers. Default format is"#.###". SeetoString(Number, String)for details.- Parameters:
number- any instance ofNumber- Returns:
- string representation of a given number.
-
toString
public static String toString(Number number, String pattern)
Formatting method for numbers. Usespatternparameter for defining output format. Format symbols:
Some examples:Symbol Location Symbol Meaning 0 Number Digit # Number Digit, zero shows as absent . Number . Decimal separator or monetary decimal separator - Number - Minus sign , Number , Grouping separator E Number E Separates mantissa and exponent in scientific notation. Need not be quoted in prefix or suffix. ; Subpattern boundary Separates positive and negative subpatterns % Prefix or suffix % Multiply by 100 and show as percentage ‰ Prefix or suffix ‰ Multiply by 1000 and show as per mille value ' Prefix or suffix Used to quote special characters in a prefix or suffix, for example, "'#'#" formats 123 to "#123". To create a single quote itself, use two in a row: "# o''clock". Pattern Number Result Comment 0000 42 0042 0000.000 42.42 0042.420 0000.000 42 0042.000 #.## 3000.452 3000.45 #.## 3000.4 3000.4 #.## 3000 3000 #,###.# 12000 12,000#0E0 12000 1.2E4003 000;neg 0 3 003000;neg 0 -3 neg 003For negative numbers positive pattern enhanced by negative pattern is used 0% 0.03 3%0‰ 0.03 30‰'#'0'%' 3 #3%- Parameters:
number- any instance ofNumberpattern- target pattern- Returns:
- string representation of a given number.
-
-