Java Fraction Format formatToString(Double v)

Here you can find the source of formatToString(Double v)

Description

format To String

License

Open Source License

Declaration

public static String formatToString(Double v) 

Method Source Code


//package com.java2s;

import java.text.DecimalFormat;

public class Main {

    public static String formatToString(Double v) {
        if (v == null) {
            return "";
        }/*w  w w .j  a v  a 2s . com*/
        try {
            DecimalFormat sos = new DecimalFormat("###.####");
            String s = sos.format(v);
            return s;
        } catch (Exception e) {
            return v.toString();
        }
    }

    public static String formatToString(Double v, String format) {
        if (v == null) {
            return "";
        }
        try {
            DecimalFormat sos = new DecimalFormat(format);
            String s = sos.format(v);
            return s;
        } catch (Exception e) {
            return v.toString();
        }
    }
}

Related

  1. formatRate(double events, double time, String event)
  2. formatSimpleDecimal(double d)
  3. formatSpeed(float speed)
  4. formatted_string(double number)
  5. formatToEightPlaces(double pValue)
  6. formatTSYS(double tsys)
  7. formatTwoDecimalsToStr(float num)
  8. formatVersion(float versionNumber)
  9. formatWithOneDecimal(Float value)