Here you can find the source of formatDecimals(double d, int mantissa)
Parameter | Description |
---|---|
d | The double value you want re-precisioned. |
mantissa | The number of digits after the decimal place. |
public static double formatDecimals(double d, int mantissa)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { /**//w w w .j a v a2 s . co m * Change the precision of a double value, according to the new mantissa. * * @param d * The double value you want re-precisioned. * @param mantissa * The number of digits after the decimal place. * @return */ public static double formatDecimals(double d, int mantissa) { String m = ""; for (int i = 0; i < mantissa; i++) { m += "#"; } DecimalFormat decimalForm = new DecimalFormat("#." + m); return Double.valueOf(decimalForm.format(d)); } }