Android Utililty Methods String Format

List of utility methods to do String Format

Description

The list of methods to do String Format are organized into topic(s).

Method

StringformatNumberWithDecimals(Locale locale, String stringToFormat, int exactNumberOfDecimals)
Format String like a number with given decimals
return formatNumberWithDecimals(locale, stringToFormat,
        exactNumberOfDecimals, exactNumberOfDecimals);
StringformatNumberWithDecimals(Locale locale, String stringToFormat, int minimalNumberOfDecimals, int maximumNumberOfDecimals)
Format String like a number with given decimals
if (stringToFormat == null || stringToFormat.length() == 0) {
    return null;
String result = null;
DecimalFormat formatter = new DecimalFormat();
setupFormatter(formatter, locale, minimalNumberOfDecimals,
        maximumNumberOfDecimals);
result = formatter.format(Double.parseDouble(stringToFormat));
...
StringformatNumberWithThreeDecimals(Locale locale, String stringToFormat)
Format String like a number with three decimals WARNING: Only use this method to present data to the screen
return formatNumberWithDecimals(locale, stringToFormat, 3);
StringformatNumberWithTwoDecimals(Locale locale, String stringToFormat)
Format String like a number with two decimals WARNING: Only use this method to present data to the screen
return formatNumberWithDecimals(locale, stringToFormat, 2);
StringformatPriceWithThreeDecimals(Locale locale, String stringToFormat)
Format String like a price with three decimals WARNING: Only use this method to present data to the screen
return formatNumberWithDecimals(locale, stringToFormat, 3);
StringformatVolume(Locale locale, String stringToFormat)
Format String as a Volume WARNING: Only use this method to present data to the screen
if (stringToFormat == null || stringToFormat.length() == 0) {
    return null;
String result = null;
DecimalFormat formatter = new DecimalFormat();
formatter.setDecimalFormatSymbols(new DecimalFormatSymbols(locale));
formatter.setGroupingUsed(true);
formatter.setGroupingSize(3);
...
StringformatPriceWithTwoDecimals(Locale locale, String stringToFormat)
Format String like a price with two decimals WARNING: Only use this method to present data to the screen
if (stringToFormat == null || stringToFormat.length() == 0) {
    return null;
int numberStart = stringToFormat.indexOf(" ");
if (numberStart != -1
        || (stringToFormat.indexOf("$") > -1 || stringToFormat
                .indexOf("?") > -1)) {
    numberStart = Math.max(stringToFormat.indexOf("$"),
...
Stringformat(String formatString, Object... args)
format
Formatter formatter = new Formatter();
String formatedString = formatter.format(formatString, args)
        .toString();
formatter.close();
return formatedString;
StringfillSpace(String formatString, int length)
Method fill string
return fillString(formatString, length, ' ', false);
StringfillString(String formatString, int length, char fillChar, boolean leftFillFlag)
Method fill string
if (null == formatString) {
    formatString = "";
int strLen = formatString.length();
if (strLen >= length) {
    if (true == leftFillFlag) 
        return formatString.substring(strLen - length, strLen);
    else
...