Rodolfo Bandeira

Rodolfo Bandeira

software, electronics, security, devops, thoughts

Format a double number to shows two numbers after comma in JAVA

How to format a double number to shows a decimal number with two numbers after comma? (In JAVA)

import java.text.DecimalFormat;   
DecimalFormat df = new DecimalFormat("#,###.00");
df.format(1234.36);

and you can use this other way:

double x = 123.123;
System.out.printf( "%.2f", x );

Last modified:

LinkedIn
WhatsApp