/** * @author lautturi.com * Java example: format double with 2 decimal places in string */ import java.text.DecimalFormat; public class Lautturi { public static void main(String[] args) { double d = 3.14159265359; DecimalFormat df = new DecimalFormat("#.00"); String str = df.format(d); System.out.println("double : " + str ); } }
output:
double : 3.14