Java tutorial
//package com.java2s; import java.text.NumberFormat; public class Main { public static String getNumberWithFractionDigit(double value, int fracLength) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(fracLength); nf.setMinimumFractionDigits(fracLength); return nf.format(value); } }