Locale Specific Currency & Percentage | Code Factory

Reference Link : Link

Donate : Link

Locale Specific Currency

You can use the class and its static method to format a number, such as a long or double type, in a locale specific currency. Following is the example which shows how to format currency specific to a given locale −

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Locale;
import java.text.NumberFormat;
import java.util.Date;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
// Get the client's Locale
Locale locale = request.getLocale( );
NumberFormat nft = NumberFormat.getCurrencyInstance(locale);
String formattedCurr = nft.format(1000000);
System.out.println("formattedCurr : " + formattedCurr);
}

Locale Specific Percentage

You can use the class and its static method to get locale specific percentage. Following is the example which shows how to format percentage specific to a given locale −

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Locale;
import java.text.NumberFormat;
import java.util.Date;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();

// Get the client's Locale
Locale locale = request.getLocale( );
NumberFormat nft = NumberFormat.getPercentInstance(locale);
String formattedPerc = nft.format(0.51);
System.out.println("formattedPerc : " + formattedPerc);
}