Java Number Convert to numberToFormattedString(Double d)

Here you can find the source of numberToFormattedString(Double d)

Description

number To Formatted String

License

BSD License

Declaration

private static String numberToFormattedString(Double d) 

Method Source Code

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

public class Main {
    private static String numberToFormattedString(Double d) {
        String s = d.toString();/*from   w  ww.j  a  va2 s  .c  o  m*/
        if (s.endsWith(".0")) {
            return s.substring(0, s.length() - 2);
        } else if (s.length() > 7) {
            return String.format("%.6g", d);
        } else {
            return s;
        }
    }
}

Related

  1. NumberToCharacter(final Number value)
  2. numberToJson(Number number)
  3. numberToMinterm(int num, int length, int index, boolean[] output)
  4. numberToOrdinal(int i)
  5. numberToPaddedHexString(int number, int size)