Java Double Number to String doubleToStr(double d)

Here you can find the source of doubleToStr(double d)

Description

double To Str

License

Open Source License

Declaration

public static String doubleToStr(double d) 

Method Source Code

//package com.java2s;
/**/*w ww. ja va  2  s  .  c o  m*/
 * Copyright 2003 ZhongTian, Inc. All rights reserved.
 *
 * qingdao tec PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 * $Id: DBUtil.java,v 1.1 2006/05/17 09:19:30 wiserd Exp $
 * File:DBUtil.java
 * Date Author Changes
 * March 10 2003 wangdeliang Created
 */

public class Main {

    public static String doubleToStr(double d) {
        String rtn = "";
        java.text.DecimalFormat df = new java.text.DecimalFormat("###0.000000");
        rtn = df.format(d);
        return cutZero(rtn);
    }

    public static String cutZero(String v) {
        if (v.indexOf(".") > -1) {
            while (true) {
                if (v.lastIndexOf("0") == (v.length() - 1)) {
                    v = v.substring(0, v.lastIndexOf("0"));
                } else {
                    break;
                }
            }
            if (v.lastIndexOf(".") == (v.length() - 1)) {
                v = v.substring(0, v.lastIndexOf("."));
            }
        }
        return v;
    }
}

Related

  1. doubleToAtLeastString(double d, int length)
  2. doubleToCoreString(double number)
  3. doubleToDollarString(double val)
  4. doubleToFixedString(double d, int length)
  5. doubleToScientificString(double number, int fractionDigits)
  6. doubleToStr(double origin, int decimals)
  7. doubleToStr1(double d)
  8. doubleToStrFormatado(Double valor)
  9. doubleToString(double d)