Package com.norconex.commons.lang
Class PercentFormatter
java.lang.Object
com.norconex.commons.lang.PercentFormatter
- All Implemented Interfaces:
Serializable
Formats percentage as string. This class is thread-safe.
Methods expecting a denominator will always return zero percent if said
denominator is zero.
- Since:
- 1.4.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new percent formatter with no decimal precision and using the default system locale.PercentFormatter(int decimalPrecision, Locale locale) Creates a new percent formatter for the given local and decimal precision. -
Method Summary
Modifier and TypeMethodDescriptionformat(double fraction) Formats a fraction as percentage string.format(double numerator, double denominator) Formats fraction values as percentage string.static StringFormats fraction values as percentage with the given local and decimal precision.static StringFormats a fraction as percentage with the given local and decimal precision.
-
Constructor Details
-
PercentFormatter
public PercentFormatter()Creates a new percent formatter with no decimal precision and using the default system locale. -
PercentFormatter
Creates a new percent formatter for the given local and decimal precision.- Parameters:
decimalPrecision- maximum number of decimals to displaylocale- a locale
-
-
Method Details
-
format
Formats fraction values as percentage string.- Parameters:
numerator- the value to dividedenominator- the divider- Returns:
- formatted percent string
-
format
Formats a fraction as percentage string.- Parameters:
fraction- the value to format as percentage- Returns:
- formatted percent string
-
format
public static String format(double numerator, double denominator, int decimalPrecision, Locale locale) Formats fraction values as percentage with the given local and decimal precision.- Parameters:
numerator- the value to dividedenominator- the dividerdecimalPrecision- maximum number of decimals to displaylocale- a locale- Returns:
- formatted percent string
-
format
Formats a fraction as percentage with the given local and decimal precision.- Parameters:
fraction- the value to format as percentagedecimalPrecision- maximum number of decimals to displaylocale- a locale- Returns:
- formatted percent string
-