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

StringgetProgressExact(double balance, double cost)
get Progress Exact
double percent = 100.0D * balance / cost;
if (percent >= 100.0D) {
    return "100";
if (percent < 0.0D) {
    return "0";
String format = format(percent);
...
StringgetRealEye(double eye)
get Real Eye
DecimalFormat df = new DecimalFormat("#.##");
if (eye == 3.9) {
    return "0.08";
} else if (eye == 3.8) {
    return "0.06";
} else if (eye == 3.7) {
    return "0.04";
} else if (eye == 3.6) {
...
doublegetRedondeoHaciaArriba(double pTotal)
get Redondeo Hacia Arriba
if (pTotal > 0.00) {
    String myTotal = formatNumber(pTotal);
    int myRedondeo = Integer.parseInt(myTotal.substring(myTotal.length() - 1, myTotal.length()));
    if (myRedondeo > 5) {
        return (0.01 * (10 - myRedondeo));
    } else if (myRedondeo > 0) {
        return (0.01 * (5 - myRedondeo));
    } else {
...
StringgetScientificNotation(double value)
get Scientific Notation
NumberFormat formatter = new DecimalFormat("0.0E0");
formatter.setRoundingMode(RoundingMode.HALF_UP);
formatter.setMinimumFractionDigits(NUMBER_DECIMAL_PLACES);
return formatter.format(value);
StringgetSpaceMessage(final double bytes)
get Space Message
if (bytes < (KILO * 0.8)) {
    return bytes + "B";
if (bytes < (MEGA * 0.8)) {
    final double kilos = bytes / KILO;
    return SPACE_FORMAT.format(kilos) + "kB";
if (bytes < (GIGA * 0.8)) {
...
StringgetStandardDeviationString(double[] standardDeviationDoubles)
get Standard Deviation String
if (standardDeviationDoubles == null) {
    return null;
StringBuilder standardDeviationString = new StringBuilder(standardDeviationDoubles.length * 9);
DecimalFormat exponentialFormat = new DecimalFormat("0.0#E0");
DecimalFormat decimalFormat = new DecimalFormat("0.0#");
boolean first = true;
for (double standardDeviationDouble : standardDeviationDoubles) {
...
StringgetStandardDouble(double d, int pL)
get Standard Double
String format = "0.";
for (int i = 0; i < pL; i++)
    format += "0";
return ((new DecimalFormat(format)).format(d));
StringgetString(Double d)
get String
NumberFormat nf = NumberFormat.getInstance();
nf.setGroupingUsed(false);
return nf.format(d);
StringgetStringFromDouble(double number)
get String From Double
DecimalFormat df = new DecimalFormat("#.###");
return df.format(number);
StringgetStringRepresentationForDouble(double value)

Returns the string representation of a double value which can be used in a DML script.

NumberFormat nf = DecimalFormat.getInstance(new Locale("EN"));
nf.setGroupingUsed(false);
nf.setMinimumFractionDigits(1);
nf.setMaximumFractionDigits(20);
return nf.format(value);