Java Double Number Format shorten(double num)

Here you can find the source of shorten(double num)

Description

shorten

License

LGPL

Declaration

public static String shorten(double num) 

Method Source Code


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

import java.text.DecimalFormat;

public class Main {
    public static String shorten(double num) {
        String string = Double.toString(num);
        if (Integer.parseInt(string.split("\\.")[1]) == 0) {
            return string.split("\\.")[0];
        } else {//from   w w  w  .  j a va  2 s  .c om
            DecimalFormat format = new DecimalFormat("0.##");
            return format.format(num);
        }
    }
}

Related

  1. getTwoDecimalByDecimalFormat(double number)
  2. getValidString(Double value, DecimalFormat formatter)
  3. isDoubleWhitFormat(String pValue)
  4. prettyDecimalFormat(double d, int numPlaces)
  5. roundFormat(double d, int i)
  6. toDoubleFromHumanFormat(String doubleAsString)
  7. toString(double in, String format)
  8. toString(double[] arr, NumberFormat nf)
  9. toString(double[] y, Format format)