Java Double Number Format formatDouble(double val)

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

Description

format Double

License

Open Source License

Declaration

protected static String formatDouble(double val) 

Method Source Code

//package com.java2s;

public class Main {
    protected static String formatDouble(double val) {
        String out = String.valueOf(val);
        if (out.length() > 5) {
            boolean round = false;
            if (round && out.charAt(5) != '.')
                if (Integer.parseInt(String.valueOf(out.charAt(5))) > 4)
                    round = true;//from  ww  w  . ja  va2s.  c  om
            out = out.substring(0, 5);
            if (round && out.charAt(4) != '.')
                out = out.substring(0, 4) + String.valueOf(Integer.parseInt(String.valueOf(out.charAt(4))) + 1);
            else
                // trim off final decimal point
                out = out.substring(0, 4);
        }
        return out;
    }
}

Related

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