|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavatools.parsers.NumberFormatter
public class NumberFormatter
This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools).
It is licensed under the Creative Commons Attribution License
(see http://creativecommons.org/licenses/by/3.0) by
the YAGO-NAGA team (see http://mpii.de/yago-naga).
This class is a simple number formatter. Furthermore, this class offers some methods for the
ISO8601 time format
Example:
System.out.println(new NumberFormatter("+##.###").format(3.1119)); --> +03.112 System.out.println(NumberFormatter.ISOtime()); --> 2006-01-17 T 21:01:00.000 System.out.println(NumberFormatter.ISOweekTime()); --> 2006-w03-2 T 21:01:00.000The pattern for numbers may look like
[+|-|+/-] #*[x]#* [.#*]without blanks. 'x' is a separator character for groups of 3 digits. Only one x will be recognized and it will always separate groups of 3, no matter where it appears. Examples:
+###.##### -# +/-#.###### ## +#'###'###.##If the formatted number is negative, a negative sign is always output. If the number is positive, a sign will only be output if the pattern starts with "+" or "+/-". The output will contain at least as many digits as specified in the pattern. If the integer part of a number contains more digits than specified in the pattern, the digits will be output nevertheless. If the fractional part of a number contains more digits than specified in the pattern, the number will be rounded and the digits will not be output. Instead of '#', you may write digits.
Field Summary | |
---|---|
static NumberFormatter |
fiveDigits
Predefined NumberFormatter for ##### |
static NumberFormatter |
fourDigits
Predefined NumberFormatter for #### |
static NumberFormatter |
fourFractions
Predefined NumberFormatter for #.#### |
static NumberFormatter |
oneDigit
Predefined NumberFormatter for # |
static NumberFormatter |
sixDigits
Predefined NumberFormatter for ###### |
static NumberFormatter |
threeDigits
Predefined NumberFormatter for ### |
static NumberFormatter |
twoDigits
Predefined NumberFormatter for ## |
static NumberFormatter |
twoFractions
Predefined NumberFormatter for #.## |
Constructor Summary | |
---|---|
NumberFormatter(java.lang.String f)
Creates a NumberFormatter for a pattern |
Method Summary | |
---|---|
java.lang.String |
format(double d)
Converts a double to a String |
static java.lang.String |
formatMS(long ms)
Converts milliseconds to a nice String |
static java.lang.String |
ISOdate()
Returns an ISO8601 string representation of the current date |
static java.lang.String |
ISOdate(java.util.Calendar c)
Returns an ISO8601 string representation of the time given by the calendar |
static java.lang.String |
ISOtime()
Returns an ISO8601 string representation of the current time |
static java.lang.String |
ISOtime(java.util.Calendar c)
Returns an ISO8601 string representation of the time given by the calendar |
static java.lang.String |
ISOweekTime()
Returns an ISO8601 string representation of the current time, using a week-oriented representation |
static java.lang.String |
ISOweekTime(java.util.Calendar c)
Returns an ISO8601 string representation of the time given by the calendar, using a week-oriented representation |
static void |
main(java.lang.String[] argv)
Test routine |
static java.lang.String |
timeStamp()
Returns a current timestamp |
static java.lang.String |
timeStamp(java.util.Calendar c)
Returns a timestamp from a Calendar |
static java.lang.String |
timeStamp(java.lang.String isoTime)
Returns a timestamp from an ISOweekTime or an ISOtime |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static NumberFormatter sixDigits
public static NumberFormatter fiveDigits
public static NumberFormatter fourDigits
public static NumberFormatter threeDigits
public static NumberFormatter twoDigits
public static NumberFormatter oneDigit
public static NumberFormatter fourFractions
public static NumberFormatter twoFractions
Constructor Detail |
---|
public NumberFormatter(java.lang.String f)
Method Detail |
---|
public java.lang.String format(double d)
public static java.lang.String ISOtime()
public static java.lang.String ISOtime(java.util.Calendar c)
public static java.lang.String ISOdate()
public static java.lang.String ISOdate(java.util.Calendar c)
public static java.lang.String ISOweekTime()
public static java.lang.String ISOweekTime(java.util.Calendar c)
public static java.lang.String timeStamp(java.lang.String isoTime)
public static java.lang.String timeStamp(java.util.Calendar c)
public static java.lang.String timeStamp()
public static java.lang.String formatMS(long ms)
public static void main(java.lang.String[] argv)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |