Java Utililty Methods Long Number Format

List of utility methods to do Long Number Format

Description

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

Method

Stringformat(long s)
format
if (s < 10) {
    return "0" + s;
} else {
    return "" + s;
Stringformat(long seconds)
format
long minutes = seconds / 60;
long secs = seconds - (minutes * 60);
String time = "" + minutes + ":";
if (secs < 10) {
    time += "0";
time += secs;
return time;
...
Stringformat(long value)
format
if (value < 0)
    return "-" + format(-value);
if (value == 0)
    return "0B";
final int mag = (int) (Math.log10(value) / Math.log10(1024));
final float adjustedSize = (float) value / (1L << (mag * 10));
final String format = (mag > 2 ? "%.2f" : "%.0f") + "%s";
return String.format(format, adjustedSize, SIZE_SUFFIXES[mag]);
...
longformat(Long value)
Converts Byte values into Megabyte values.
return value / 1024 / 1024;
StringformatLong(long inLong, int inLen, boolean inComma, int inCommaPos)
This method is to format the long.
String outString = "";
int countComma = 0;
long tempLong;
boolean fNegative = false;
if (inLong < 0) {
    fNegative = true;
    inLong = inLong * (-1);
if (inLong == 0)
    outString = "0";
else {
    while (inLong > 0) {
        if (inComma && countComma == inCommaPos) {
            outString = "," + outString;
            countComma = 0;
        tempLong = inLong % 10;
        outString = Long.toString(tempLong) + outString;
        inLong = (long) (inLong / 10);
        countComma++;
if (fNegative)
    outString = "-" + outString;
return outString;
StringformatLong(Long number)
format Long
if (number == null) {
    number = 0L;
return number.toString();
StringformatLong(long val, int size)
format Long
String formatter = "%0" + size + "d";
return String.format(formatter, val);
StringformatLong(long value)
Formats a long value and prepends it with a - or + This functions is used for showing the diff values for test runs
if (value == 0) {
    return "0";
} else if (value < 0) {
    return Long.toString(value);
} else { 
    return "+" + Long.toString(value);
StringformatLong(long value)
Formats a value using spaces to separate thousands as: ddd ddd ddd.
boolean isNegative = value < 0;
if (isNegative) {
    value = -value;
char[] buffer = new char[1 + 19 + 6];
int index = buffer.length - 1;
if (value == 0) {
    buffer[index--] = '0';
...
StringformatLong(long value, int length)
Format long value
boolean isPostive = value >= 0;
value = isPostive ? value : value * -1;
String result = formatStr2("" + value, length - 1);
if (isPostive)
    result = " " + result;
else
    result = "-" + result;
return result;
...