Package com.norconex.commons.lang
Class PercentFormatter
- java.lang.Object
-
- com.norconex.commons.lang.PercentFormatter
-
- All Implemented Interfaces:
Serializable
public class PercentFormatter extends Object implements 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
- Author:
- Pascal Essiembre
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PercentFormatter()Creates 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringformat(double fraction)Formats a fraction as percentage string.Stringformat(double numerator, double denominator)Formats fraction values as percentage string.static Stringformat(double numerator, double denominator, int decimalPrecision, Locale locale)Formats fraction values as percentage with the given local and decimal precision.static Stringformat(double fraction, int decimalPrecision, Locale locale)Formats a fraction as percentage with the given local and decimal precision.
-
-
-
Constructor Detail
-
PercentFormatter
public PercentFormatter()
Creates a new percent formatter with no decimal precision and using the default system locale.
-
PercentFormatter
public PercentFormatter(int decimalPrecision, Locale locale)Creates a new percent formatter for the given local and decimal precision.- Parameters:
decimalPrecision- maximum number of decimals to displaylocale- a locale
-
-
Method Detail
-
format
public String format(double numerator, double denominator)
Formats fraction values as percentage string.- Parameters:
numerator- the value to dividedenominator- the divider- Returns:
- formatted percent string
-
format
public String format(double fraction)
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
public static String format(double fraction, int decimalPrecision, Locale locale)
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
-
-