Java tutorial
//package com.java2s; import java.math.BigDecimal; import java.math.MathContext; public class Main { /** * Returns a string representation of number rounded to given number of * significant figures * * @param value * @param significantFigures * @return String. */ public static String roundToString(double value, int significantFigures) { MathContext mc = new MathContext(significantFigures); BigDecimal num = new BigDecimal(value); return num.round(mc).toPlainString(); } }