Java Double Number Format formatDoubleAsString(double num, int n)

Here you can find the source of formatDoubleAsString(double num, int n)

Description

format Double As String

License

Open Source License

Declaration

public static String formatDoubleAsString(double num, int n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String formatDoubleAsString(double num, int n) {
        String ret = String.format("%." + n + "f", num).replace(',', '.');
        if (ret.length() > 5) {
            ret = String.format("%5.2e", Double.parseDouble(ret));
        }//from ww w  .  java 2s .c o m
        return ret;
    }
}

Related

  1. formatDouble(double value)
  2. formatDouble(double value, int decimals)
  3. formatDouble(final double value)
  4. formatDouble(final Object value)
  5. formatDouble(String value)
  6. formatDoubleFast(double source, int decimals, int precision, StringBuffer target)
  7. formatDoubleForDecimalPlaces(double d, int decimalcount)
  8. formatDoubleInfinity(Double d)
  9. formatDoublePrecise(double source, int decimals, int precision, StringBuffer target)