Quantcast
Channel: web development helpdesk » double
Viewing all articles
Browse latest Browse all 6

How to format a double as a String?

$
0
0
Create an instance of DecimalFormat with the required format and use its format() method to format the double value. See the DecimalFormat javadoc for details on specifying format. double d = 1.23456789; // Use 2 decimal places NumberFormat numberFormat = new DecimalFormat("#.##"); String s = numberFormat.format(d); System.out.println(s); // Outputs: 1.23

Viewing all articles
Browse latest Browse all 6

Trending Articles