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 void print(long value) {
    System.out.println(String.format(Locale.US, "$%,.2f", (double) value / 100));
}

From source file:Main.java

public static String getLabelForDuration(int ms) {
    if (ms <= 0) {
        return null;
    }//from  w  w  w  .  j  av a 2  s.  c  o m
    return String.format("%02d:%02d", Integer.valueOf(ms / 60000), Integer.valueOf(ms / 1000 % 60));
}

From source file:Main.java

public static String getLocaleLanguage() {
    Locale l = Locale.getDefault();
    return String.format("%s-%s", l.getLanguage(), l.getCountry());
}

From source file:Main.java

public static void checkPositiveOrZero(float number, String name) {
    if (number < 0)
        throw new IllegalArgumentException(String.format("%s %d must be positive", name, number));
}

From source file:Main.java

public static String getPercentString(float percent) {
    return String.format(Locale.US, "%d%%", (int) (percent * 100));
}

From source file:Main.java

public static String genSharePath(String path) {
    String module = path.split("/")[0];
    return String.format("/md-%s/dist/%s", module, path);
}

From source file:Main.java

public static String getFuzzyIp(String ip) {
    final String[] ipParts = ip.split("\\.");
    if (ipParts.length == 4) {
        return String.format("%s.%s.*.*", ipParts[0], ipParts[1]);
    }//from  ww w .  j av  a  2 s  .c  o m

    return ip;
}

From source file:Main.java

public static String getTimeText(int sec) {
    sec = (int) sec / 1000;
    int minutes = (int) sec / 60;
    sec = sec % 60;//from w  w  w. j a va2  s.  c  o  m

    return String.format("%02d:%02d", minutes, sec);
}

From source file:Main.java

/**
 * Composes the xml for an authtoken request
 *//*from  w  w w.j a v a2s . c o  m*/
public static String composeAuthTokenRequestXml(String email, String password) {
    return String.format("<user><email>%s</email><password>%s</password></user>", email, password);
}

From source file:Main.java

/**
 * @return/*from   w  w  w . j  av  a 2 s.com*/
 */
public static String calculateAltitudeFromMSL(float msl) {
    double altitude = msl;
    return (String.format(Locale.getDefault(), "%d", (int) altitude));
}