Example usage for java.lang String format

List of usage examples for java.lang String format

Introduction

In this page you can find the example usage for java.lang String format.

Prototype

public static String format(Locale l, String format, Object... args) 

Source Link

Document

Returns a formatted string using the specified locale, format string, and arguments.

Usage

From source file:Main.java

public static String formatFloat(float value) {
    return String.format(Locale.getDefault(), "%.3f", value);
}

From source file:Main.java

public static String formatPrice(double price) {
    return String.format(Locale.getDefault(), "%.1f", price);
}

From source file:Main.java

public static String formatAmount(double value) {
    return String.format(Locale.getDefault(), "%.2f", value);
}

From source file:Main.java

public static String getCustomerId(String userId) {
    return String.format(Locale.CHINA, "u_%s", userId).toLowerCase(Locale.CHINA);
}

From source file:Main.java

public static String formatPrice(String prefix, float value) {
    return String.format(Locale.US, prefix + "%.2f", value);
}

From source file:Main.java

public static String miliSecondToString(long pTime) {
    int second = (int) (pTime / 1000);
    return String.format("%02d:%02d", second / 60, second % 60);
}

From source file:Main.java

private static String getVersionSubdirectoryName(int version) {
    return String.format((Locale) null, "%s.ols%d.%d",
            new Object[] { "v2", Integer.valueOf(100), Integer.valueOf(version) });
}

From source file:Main.java

public static String formatFloat(float t) {
    try {/*from   w  w w  . j av a 2s . c  o  m*/
        return String.format(Locale.US, "%.1f", t);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "0.0";
}

From source file:Main.java

public static float roundFloatTwoHouse(float value) {

    return Float.parseFloat(String.format(Locale.US, "%.2f", value));
}

From source file:Main.java

public static String milisecondsToMinuteString(long miliseconds) {
    return String.format("%d:%02d", TimeUnit.MILLISECONDS.toMinutes(miliseconds),
            TimeUnit.MILLISECONDS.toSeconds(miliseconds)
                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(miliseconds)));
}