er.extensions
Class ERXUnitAwareDecimalFormat
java.lang.Object
java.text.Format
java.text.NumberFormat
java.text.DecimalFormat
er.extensions.ERXUnitAwareDecimalFormat
- All Implemented Interfaces:
- Cloneable, Serializable
- public class ERXUnitAwareDecimalFormat
- extends DecimalFormat
- implements Cloneable, Serializable
ERXUnitAwareDecimalFormat
extends DecimalFormat
to add an automatic unit conversion feature for
the given unit. Convenient to display friendly values
for file size, elaps time, etc.
Examples:
import java.text.NumberFormat;
import er.extensions.ERXUnitAwareDecimalFormat
double smallValue = 123.0d;
double largeValue = 1234567890.0d;
NumberFormat formatter = new ERXUnitAwareDecimalFormat(ERXUnitAwareDecimalFormat.BYTE);
formatter.setMaximumFractionDigits(2);
// Will display "123 bytes"
System.out.println(formatter.format(smallValue));
// Will display "1.15 GB"
System.out.println(formatter.format(largeValue));
- See Also:
- Serialized Form
Field Summary |
static String |
BYTE
Predefined computer mass unit; supports: bytes, KB, MB, GB, TB |
static String |
GRAM
Predefined metric weight unit; supports: mg, g, kg, ton, kiloton |
static String |
METER
Predefined metric length unit; supports: nm, micrometer, mm, cm, m, km |
static String |
SECOND
Predefined time unit; supports: ps, ns, microsecond, ms, sec, min, hour, day |
protected NSArray |
unitPrefixArray
|
Methods inherited from class java.text.DecimalFormat |
applyLocalizedPattern, applyPattern, clone, equals, formatToCharacterIterator, getCurrency, getDecimalFormatSymbols, getGroupingSize, getMultiplier, getNegativePrefix, getNegativeSuffix, getPositivePrefix, getPositiveSuffix, hashCode, isDecimalSeparatorAlwaysShown, parse, setCurrency, setDecimalFormatSymbols, setDecimalSeparatorAlwaysShown, setGroupingSize, setMaximumFractionDigits, setMaximumIntegerDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setMultiplier, setNegativePrefix, setNegativeSuffix, setPositivePrefix, setPositiveSuffix, toLocalizedPattern, toPattern |
Methods inherited from class java.text.NumberFormat |
format, format, format, getAvailableLocales, getCurrencyInstance, getCurrencyInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, getNumberInstance, getNumberInstance, getPercentInstance, getPercentInstance, isGroupingUsed, isParseIntegerOnly, parse, parseObject, setGroupingUsed, setParseIntegerOnly |
BYTE
public static final String BYTE
- Predefined computer mass unit; supports: bytes, KB, MB, GB, TB
- See Also:
- Constant Field Values
METER
public static final String METER
- Predefined metric length unit; supports: nm, micrometer, mm, cm, m, km
- See Also:
- Constant Field Values
GRAM
public static final String GRAM
- Predefined metric weight unit; supports: mg, g, kg, ton, kiloton
- See Also:
- Constant Field Values
SECOND
public static final String SECOND
- Predefined time unit; supports: ps, ns, microsecond, ms, sec, min, hour, day
- See Also:
- Constant Field Values
unitPrefixArray
protected final NSArray unitPrefixArray
ERXUnitAwareDecimalFormat
public ERXUnitAwareDecimalFormat()
ERXUnitAwareDecimalFormat
public ERXUnitAwareDecimalFormat(String unitName)
ERXUnitAwareDecimalFormat
public ERXUnitAwareDecimalFormat(NSArray unitPrefixArray)
ERXUnitAwareDecimalFormat
public ERXUnitAwareDecimalFormat(String pattern,
DecimalFormatSymbols symbols)
ERXUnitAwareDecimalFormat
public ERXUnitAwareDecimalFormat(String pattern,
DecimalFormatSymbols symbols,
String unitName)
ERXUnitAwareDecimalFormat
public ERXUnitAwareDecimalFormat(String pattern,
DecimalFormatSymbols symbols,
NSArray unitPrefixArray)
format
public StringBuffer format(double number,
StringBuffer toAppendTo,
FieldPosition fieldPosition)
format
public StringBuffer format(long number,
StringBuffer toAppendTo,
FieldPosition fieldPosition)
Copyright © 2002 – 2004 Project Wonder.