Add formating methods for percentages, currencies and big numbers

This commit is contained in:
Marcin Krykowski
2020-06-13 23:40:19 +01:00
parent 3396e92d2d
commit e3f7cf6b2c
2 changed files with 71 additions and 0 deletions
@@ -40,5 +40,34 @@ public class FormatNumber {
public static String withStringFormat(double value, int places) {
return String.format("%." + places + "f", value);
}
public static String byPaddingOutZeros(int value, int paddingLength) {
return String.format("%0" + paddingLength + "d", value);
}
public static double withTwoDecimalPlaces(double value) {
DecimalFormat df = new DecimalFormat("#.00");
return new Double(df.format(value));
}
public static String withLongNumbers(double value) {
DecimalFormat df = new DecimalFormat("###,###,###");
return df.format(value);
}
public static String forPercentages(double value, Locale localisation) {
NumberFormat nf = NumberFormat.getPercentInstance(localisation);
return nf.format(value);
}
public static String currencyWithChosenLocalisation(double value, Locale localisation) {
NumberFormat nf = NumberFormat.getCurrencyInstance(localisation);
return nf.format(value);
}
public static String currencyWithDefaultLocalisation(double value) {
NumberFormat nf = NumberFormat.getCurrencyInstance();
return nf.format(value);
}
}