Following example shows how to format the string by using Locale and format() method.
Sample Program
package com.javatutorialcorner.javastring;
import java.util.Locale;
public class StringFormat {
public static void main(String[] args) {
double input = Math.E;
System.out.format("%f%n", input);
System.out.format(Locale.US, "%f%n", input);
System.out.format(Locale.UK, "%f%n", input);
System.out.format(Locale.ITALY, "%f%n", input);
System.out.format(Locale.ITALY, "%-10.4f%n%n", input);
System.out.format(Locale.GERMANY, "%f%n", input);
System.out.format(Locale.GERMANY, "%-10.4f%n%n", input);
}
}
Result
The above code will produce the following result
2.718282
2.718282
2.718282
2,718282
2,71832,718282
2,7183
0 comments:
Post a Comment