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, elapsed 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));
Modifier and Type | Class and Description |
---|---|
static class |
ERXUnitAwareDecimalFormat.UnitPrefix
UnitPrefix is an inner class
|
NumberFormat.Field
Modifier and Type | Field and Description |
---|---|
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 |
FRACTION_FIELD, INTEGER_FIELD
Constructor and Description |
---|
ERXUnitAwareDecimalFormat() |
ERXUnitAwareDecimalFormat(NSArray unitPrefixArray) |
ERXUnitAwareDecimalFormat(String unitName) |
ERXUnitAwareDecimalFormat(String pattern,
DecimalFormatSymbols symbols) |
ERXUnitAwareDecimalFormat(String pattern,
DecimalFormatSymbols symbols,
NSArray unitPrefixArray) |
ERXUnitAwareDecimalFormat(String pattern,
DecimalFormatSymbols symbols,
String unitName) |
Modifier and Type | Method and Description |
---|---|
StringBuffer |
format(double number,
StringBuffer toAppendTo,
FieldPosition fieldPosition) |
StringBuffer |
format(long number,
StringBuffer toAppendTo,
FieldPosition fieldPosition) |
applyLocalizedPattern, applyPattern, clone, equals, format, formatToCharacterIterator, getCurrency, getDecimalFormatSymbols, getGroupingSize, getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, getMultiplier, getNegativePrefix, getNegativeSuffix, getPositivePrefix, getPositiveSuffix, getRoundingMode, hashCode, isDecimalSeparatorAlwaysShown, isParseBigDecimal, parse, setCurrency, setDecimalFormatSymbols, setDecimalSeparatorAlwaysShown, setGroupingSize, setGroupingUsed, setMaximumFractionDigits, setMaximumIntegerDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setMultiplier, setNegativePrefix, setNegativeSuffix, setParseBigDecimal, setPositivePrefix, setPositiveSuffix, setRoundingMode, toLocalizedPattern, toPattern
format, format, getAvailableLocales, getCurrencyInstance, getCurrencyInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getNumberInstance, getNumberInstance, getPercentInstance, getPercentInstance, isGroupingUsed, isParseIntegerOnly, parse, parseObject, setParseIntegerOnly
format, parseObject
public static final String BYTE
public static final String METER
public static final String GRAM
public static final String SECOND
protected final NSArray unitPrefixArray
public ERXUnitAwareDecimalFormat()
public ERXUnitAwareDecimalFormat(String unitName)
public ERXUnitAwareDecimalFormat(NSArray unitPrefixArray)
public ERXUnitAwareDecimalFormat(String pattern, DecimalFormatSymbols symbols)
public ERXUnitAwareDecimalFormat(String pattern, DecimalFormatSymbols symbols, String unitName)
public ERXUnitAwareDecimalFormat(String pattern, DecimalFormatSymbols symbols, NSArray unitPrefixArray)
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition fieldPosition)
format
in class DecimalFormat
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition fieldPosition)
format
in class DecimalFormat
Copyright © 2002 – 2020 Project Wonder.