Sunday 13, Apr 2025
We are moved to new domain
Click -> www.ehowtonow.com
Friday, 8 May 2015

How to format the String by using Locale

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,7183   

2,718282
2,7183   

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer

Related Posts:

  • Java 8 convert List to Map example In this article we are going to see about how to convert a List of objects into a Map using Java 8 with example program StockMarket.java package com.javatutorialcorner.java8; public class StockMarket { private int id; p… Read More
  • Introduction to Java Virtual Machine (JVM) What is JVM A Java virtual machine (JVM) is an abstract computing machine that enables a computer to run a Java program. There are three notions of the JVM: 1. Specification 2. Implementation 3. Instance. The specification… Read More
  • First Java Application in Eclipse In this tutorial we are going to see about "how to create Java Project in Eclipse.Step by step procedure to create Java Project using Eclipse given below. Read detail explanation of  First Java Program Follow the … Read More
  • Java 8 convert List to Map with Duplicate Keys example In this article we are going to see about how to convert a List with duplicate key into a Map using Java 8 with example program. StockMarket.java package com.javatutorialcorner.java8; public class StockMarket { private i… Read More
  • First Java Program In this tutorial we are going to see about details of "First Java Program. To read how to create and run First Java Application in Eclipse HelloWorld.java package com.javatutorialcorner.java; public class HelloWorld … Read More
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: How to format the String by using Locale Rating: 5 Reviewed By: eHowToNow