Format double value as a percentage in Java
Description
The following code shows how to format double value as a percentage.
Example
/*from ww w . j a v a 2s. co m*/
import java.text.DecimalFormat;
public class Main {
public static void main(String[] argv) throws Exception {
DecimalFormat df = new DecimalFormat("#%");
System.out.println(df.format(0.19));
System.out.println(df.format(-0.19));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »