Java Utililty Methods Number Convert to

List of utility methods to do Number Convert to

Description

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

Method

CharacterNumberToCharacter(final Number value)
Number To Character
return value == null ? null : (char) value.intValue();
StringnumberToFormattedString(Double d)
number To Formatted String
String s = d.toString();
if (s.endsWith(".0")) {
    return s.substring(0, s.length() - 2);
} else if (s.length() > 7) {
    return String.format("%.6g", d);
} else {
    return s;
StringnumberToJson(Number number)
number To Json
return number.toString();
voidnumberToMinterm(int num, int length, int index, boolean[] output)
encode the number as a boolean vector, starting from the given index.
for (int i = 0; i < length; i++)
    output[index++] = ((num & (1L << i)) != 0);
StringnumberToOrdinal(int i)
number To Ordinal
return i % 100 == 11 || i % 100 == 12 || i % 100 == 13 ? i + "th" : i + ORDINAL_SUFFIXES[i % 10];
StringnumberToPaddedHexString(int number, int size)
number To Padded Hex String
String s = Integer.toHexString(number);
if (s.length() > size) {
    throw new IllegalArgumentException("Number too big for padded hex string");
StringBuffer buf = new StringBuffer();
for (int i = 0; i < (size - s.length()); i++) {
    buf.append('0');
buf.append(s);
return buf.toString();
longnumberToPrimitiveLong(Object o)
number To Primitive Long
long i;
if (o instanceof Long)
    i = ((Long) o).longValue();
else if (o instanceof Integer)
    i = ((Integer) o).longValue();
else if (o instanceof Short)
    i = ((Short) o).longValue();
else if (o instanceof Byte)
...
DoubleNumberToReal(Object n)
converts a instance to a Double.
if (n == null)
    return null;
return new Double(((Number) n).doubleValue());