Java Double Number Format formatDouble(double val)

Here you can find the source of formatDouble(double val)

Description

format Double

License

Apache License

Declaration

public static String formatDouble(double val) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String formatDouble(double val) {
        String num = String.format("%.2f", val);
        if (!num.startsWith("-")) {
            return pad(" " + num, 6);
        } else {//www.java2  s .  com
            return pad(num, 6);
        }

    }

    public static String pad(String text, int totalLength) {
        StringBuffer sb = new StringBuffer(text);
        while (sb.length() < totalLength) {
            sb.append(" ");
        }
        return sb.toString();
    }
}

Related

  1. formatDouble(double inDouble, boolean inComma, int inCommaPos)
  2. formatDouble(double num, int width, int precision)
  3. FormatDouble(double p_value, int p_numberOfDecimalPlaces)
  4. formatDouble(double source, int decimals, int precision)
  5. formatDouble(double v, int decimalPlaces)
  6. formatDouble(double val)
  7. formatDouble(double val, int prec)
  8. formatDouble(double val, int precision)
  9. formatDouble(double value)