Example usage for java.lang Long toString

List of usage examples for java.lang Long toString

Introduction

In this page you can find the example usage for java.lang Long toString.

Prototype

public static String toString(long i) 

Source Link

Document

Returns a String object representing the specified long .

Usage

From source file:Main.java

/**
 * prepare long value used as amount for display
 * (implicit 2 decimals)/*  w w  w  .j  av a 2s  .  com*/
 * @param l value
 * @param len display len
 * @return formated field
 * @exception ISOException
 */
public static String formatAmount(long l, int len) {
    String buf = Long.toString(l);
    if (l < 100)
        buf = zeropad(buf, 3);
    StringBuilder s = new StringBuilder(padleft(buf, len - 1, ' '));
    s.insert(len - 3, '.');
    return s.toString();
}

From source file:Main.java

public static String formatSize(long size) {
    String suffix = null;//from ww w.  java 2  s  .  c  o  m

    if (size >= 1024) {
        suffix = "KB";
        size /= 1024;
        if (size >= 1024) {
            suffix = "MB";
            size /= 1024;
        }
    }

    StringBuilder resultBuffer = new StringBuilder(Long.toString(size));

    int commaOffset = resultBuffer.length() - 3;
    while (commaOffset > 0) {
        resultBuffer.insert(commaOffset, ',');
        commaOffset -= 3;
    }

    if (suffix != null) {
        resultBuffer.append(suffix);
    }

    return resultBuffer.toString();
}

From source file:Main.java

public static String trans2FreeAndTotalMem(long[] memInfo) {
    return Long.toString(memInfo[1] + memInfo[2] + memInfo[3]) + "M/" + Long.toString(memInfo[0]) + "M";
}