Java Long to String longToString(long value)

Here you can find the source of longToString(long value)

Description

Convert a Long number to a readable string.

License

Open Source License

Parameter

Parameter Description
value long number.

Return

the "human-friendly" (readable) number as a String.

Declaration

public static String longToString(long value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from w  w w. j  a v a2 s.  c  o m
     * Convert a Long number to a readable string.
     *
     * @param value long number.
     * @return the "human-friendly" (readable) number as a String.
     */
    public static String longToString(long value) {
        return value >= 1e11 ? String.format("%.0fG", value / 1e9)
                : value >= 1e7 ? String.format("%.0fM", value / 1e6)
                        : (value >= 1e4) ? String.format("%.0fK", value / 1e3) : Long.toString(value);
    }
}

Related

  1. longToString(long n)
  2. LongToString(long number, boolean bcdFlag, int bufferSize)
  3. longToString(long val)
  4. longToString(long value)
  5. longToString(long value)
  6. LongToString(long value)
  7. longToString(Long value)
  8. longToString(long[] values)