Java Utililty Methods Decimal Format

List of utility methods to do Decimal Format

Description

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

Method

StringgetTwoPoint(double val)
get Two Point
DecimalFormat nf = new DecimalFormat("0.00");
return nf.format(val);
StringgetValue(double value)
Gets the value.
if (isNotSet(value)) {
    return "";
return format(value);
booleanisDouble(String _str)
Checks if the given string is a valid double (including negative values).
return isDouble(_str, true);
booleanisLikelyDouble(long value)
is Likely Double
if (value == canonicalDoubleNaN || value == maxDouble || value == piDouble || value == eDouble) {
    return true;
if (value == Long.MAX_VALUE || value == Long.MIN_VALUE) {
    return false;
double doubleValue = Double.longBitsToDouble(value);
if (Double.isNaN(doubleValue)) {
...
doubleisprime(double x)
isprime
if ((Math.round(x) != toFix(x, 12)) || (x < 2)) {
    throw new IllegalArgumentException("isPrime(n), where n >= 2 is an integer");
} else {
    long n = Math.round(x);
    for (long i = 2; i <= Math.sqrt(n); i++) {
        double factor = n * 1.0 / i;
        if (Math.round(factor) == toFix(factor, 12))
            return 0;
...
booleanisValidDouble(String value, int decimals)
Tell whether a double string is in valid format, according with a number of fraction digits.
DecimalFormat df;
df = (DecimalFormat) DecimalFormat.getInstance(Locale.getDefault());
DecimalFormatSymbols dsym = df.getDecimalFormatSymbols();
char decSepar = dsym.getDecimalSeparator();
if (value == null || value.trim().equals(""))
    return true;
value = value.trim();
if (value.indexOf(decSepar) != value.lastIndexOf(decSepar))
...
StringJulian_Cal(double JDN)
Julia Cal
int D, 
        Y, M;
double N1, N2, Y1, M1;
N1 = (JDN - 1721119.0) + 2.0;
Y1 = Math.floor((N1 - 0.2) / 365.25);
N2 = N1 - Math.floor(365.25 * Y1);
M1 = Math.floor((N2 - 0.5) / 30.6);
D = (int) (N2 - 30.6 * M1 + 0.5);
...
StringlistToString(List list)
list To String
if (list.isEmpty()) {
    return "[]";
StringBuilder str = new StringBuilder();
str.append("[").append(formatDouble(list.get(0)));
for (int i = 1; i < list.size(); i++) {
    str.append(", ").append(formatDouble(list.get(i)));
str.append("]");
return str.toString();
StringnumToString(double num)
Format an integer to a string (adding commas)
return numToString(num, 0);
Stringpad(double n)
pad
return formatter.format(n);