Java tutorial
//package com.java2s; import java.math.BigDecimal; public class Main { /** * Convert rate from double. * * @param value * the value * @return the string */ public static String convertRateFromDouble(double value) { return String.valueOf(round(value * 100, 2)); } public static double round(double v, int scale) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); } BigDecimal b = new BigDecimal(Double.toString(v)); BigDecimal one = new BigDecimal("1"); return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); } }