formatting double to 2 decimal places in Java

formatting double to 2 decimal places in Java
/**
 * @author lautturi.com
 * Java example: java format double to 2 decimal places 
 */

public class Lautturi {

	public static void main(String[] args) {

		double d = 3.14159;
		String str = String.format("%.2f",d);
        System.out.println("with 2 decimal places: "+str);
        
	}

}
Source:w‮uttual.ww‬ri.com

output:

with 2 decimal places: 3.14
Created Time:2017-09-11 16:55:09  Author:lautturi