Java Double to String doubleToString(double d)

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

Description

double To String

License

Apache License

Declaration

public static String doubleToString(double d) 

Method Source Code

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

public class Main {
    public static int DOUBLE_BYTE = 4;

    public static String doubleToString(double d) {
        int length;
        if (d < 0.0) {
            length = DOUBLE_BYTE;//from www .  jav a 2s . c  o m
        } else {
            length = DOUBLE_BYTE - 1;
        }
        double db = 1.0;
        for (int i = 1; i < length; i++) {
            db = db * 10.0;
        }
        double nd = (double) Math.round(d * db) / db;
        String str = "" + nd;
        if (str.length() < length + 1) {
            for (int i = 0; i < length + 1 - str.length(); i++) {
                str = str + "0";
            }
        } else {
            str = str.substring(0, length + 1);
        }
        return str;
    }
}

Related

  1. double2str(double d, int noOfDecimalDigit)
  2. double2string(double doubledata)
  3. double2String(double[] v)
  4. doubleToStr(Double d)
  5. doubleToStr(Double valor)
  6. doubleToString(double d)
  7. doubleToString(double d)
  8. doubleToString(double d, int fNumber)
  9. doubleToString(double d, int sigDigs)