Here you can find the source of doubleToString(double val, int digits)
Parameter | Description |
---|---|
val | the double you want to express |
digits | the max number of digits that you want |
public static String doubleToString(double val, int digits)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w ww. j av a2 s. c o m*/ * Returns a String containing the value of the double with (at most) * the specified number of digits (rounded if needed). * Ex : doubleToString(214.1234567,4) returns "214.1235", * doubleToString(3.5,5) returns "3.5". * @param val the double you want to express * @param digits the max number of digits that you want * @return */ public static String doubleToString(double val, int digits) { double d = Math.pow(10, digits); val *= d; // to avoid decimals val = Math.round(val); val /= d; return Double.toString(val); } }