Currency Symbol problem
Hi All,
My Server side code:
--------------------
NumberFormat numberFormat = NumberFormat.getCurrencyInstance();
Currency currency = Currency.getInstance("MYR"); // Malaysia Code
numberFormat.setCurrency(currency);
int num = 12345;
I want to print this in a JSP Page by using numberFormat.format(num).
When I executed the above code in a browser with setting en-us language,
it is showing MYR 12345 like that showing. I want to show this like
RM 12345.
How to solve this?
Any help or idea is greatly appreciated,
Sreenivasulu Arveti.
View Answers
October 13, 2010 at 9:26 PM
Hi,
The java.util.Locale class defines the available local:
Locale.CANADA
Locale.CANADA_FRENCH
Locale.CHINA
Locale.ENGLISH
Locale.ITALY
etc.
If you call the Currency.getInstance(local); then it will give you Currency of that local. But it some cases it Currency is not available then it will give exception. So, while getting the currency for a local put it in the try can catch block.
The following code examples prints the currency of locals if avaialble.
<pre class="prettyprintlang-java">
import java.util.Currency;
import java.util.Locale;
import java.text.DateFormatSymbols;
public class JavaCurrencySymbol {
public static void main(String[] args) {
//Getting currency symbold by specifying the locals
Currency currency = Currency.getInstance(Locale.US);
System.out.println("United States: " + currency.getSymbol());
currency = Currency.getInstance(Locale.UK);
System.out.println("United Kingdom: " + currency.getSymbol());
currency = Currency.getInstance(Locale.FRANCE);
System.out.println("France: " + currency.getSymbol());
currency = Currency.getInstance(Locale.FRANCE);
System.out.println("France: " + currency.getSymbol());
//Displaying currency symbols of all the locals
Locale[] locals = Locale.getAvailableLocales();
for (int i=0; i<locals.length; i++){
Locale local = locals[i];
Currency curr = null;
try{
curr = Currency.getInstance(local);
}catch(Exception e){
}
if(curr!=null){
System.out.println("Local is: " + local + ", Currency Symbol is: "
+ curr.getSymbol());
}else{
System.out.println("Local is: " + local );
}
}
}
}
</pre>
The output of the code is as shown below:
C:\1111>java JavaCurrencySymbol
United States: $
United Kingdom: GBP
France: EUR
France: EUR
Local is: es_PE, Currency Symbol is: PEN
Local is: en
Local is: es_PA, Currency Symbol is: PAB
Local is: sr_BA, Currency Symbol is: BAM
Local is: mk
Local is: es_GT, Currency Symbol is: GTQ
Local is: no_NO, Currency Symbol is: NOK
Local is: sq_AL, Currency Symbol is: ALL
Local is: bg
Local is: hu
Local is: pt_PT, Currency Symbol is: EUR
Local is: el_CY, Currency Symbol is: EUR
Local is: mk_MK, Currency Symbol is: MKD
Local is: sv
Local is: de_CH, Currency Symbol is: CHF
Local is: en_US, Currency Symbol is: $
Local is: fi_FI, Currency Symbol is: EUR
Local is: is
Local is: cs
Local is: en_MT, Currency Symbol is: EUR
Local is: sl_SI, Currency Symbol is: EUR
Local is: sk_SK, Currency Symbol is: SKK
Local is: it
Local is: tr_TR, Currency Symbol is: TRY
Local is: no
Local is: en_GB, Currency Symbol is: GBP
Local is: sr_CS, Currency Symbol is: CSD
Local is: lt
Local is: ro
Local is: en_NZ, Currency Symbol is: NZD
Local is: no_NO_NY, Currency Symbol is: NOK
Local is: lt_LT, Currency Symbol is: LTL
Local is: es_NI, Currency Symbol is: NIO
Local is: nl
Local is: ga_IE, Currency Symbol is: EUR
Local is: fr_BE, Currency Symbol is: EUR
Local is: es_ES, Currency Symbol is: EUR
Local is: fr_CA, Currency Symbol is: CAD
Local is: et_EE, Currency Symbol is: EEK
Local is: sr_RS, Currency Symbol is: RSD
Local is: es_US, Currency Symbol is: $
Local is: es_MX, Currency Symbol is: MXN
Local is: in_ID, Currency Symbol is: IDR
Local is: ru
Local is: lv
Local is: es_UY, Currency Symbol is: UYU
Local is: lv_LV, Currency Symbol is: LVL
Local is: pt_BR, Currency Symbol is: BRL
Local is: hr
Local is: et
Local is: es_DO, Currency Symbol is: DOP
Local is: fr_CH, Currency Symbol is: CHF
Local is: es_VE, Currency Symbol is: VEF
Local is: en_PH, Currency Symbol is: PHP
Local is: fi
Local is: de_AT, Currency Symbol is: EUR
Local is: es
Local is: nl_NL, Currency Symbol is: EUR
Local is: es_EC, Currency Symbol is: $
Local is: be
Local is: is_IS, Currency Symbol is: ISK
Local is: es_CO, Currency Symbol is: COP
Local is: es_CR, Currency Symbol is: CRC
Local is: es_CL, Currency Symbol is: CLP
Local is: en_ZA, Currency Symbol is: ZAR
Local is: el_GR, Currency Symbol is: EUR
Local is: it_IT, Currency Symbol is: EUR
Local is: ca
Local is: hu_HU, Currency Symbol is: HUF
Local is: fr
Local is: en_IE, Currency Symbol is: EUR
Local is: uk_UA, Currency Symbol is: UAH
Local is: pl_PL, Currency Symbol is: PLN
Local is: fr_LU, Currency Symbol is: EUR
Local is: nl_BE, Currency Symbol is: EUR
Local is: en_IN, Currency Symbol is: INR
Local is: ca_ES, Currency Symbol is: EUR
Local is: es_BO, Currency Symbol is: BOB
Local is: en_AU, Currency Symbol is: AUD
Local is: sr
Local is: pt
Local is: uk
Local is: es_SV, Currency Symbol is: SVC
Local is: ru_RU, Currency Symbol is: RUB
Local is: sr_ME, Currency Symbol is: EUR
Local is: sq
Local is: be_BY, Currency Symbol is: BYR
Local is: bg_BG, Currency Symbol is: BGN
Local is: in
Local is: mt_MT, Currency Symbol is: EUR
Local is: es_PY, Currency Symbol is: PYG
Local is: sl
Local is: fr_FR, Currency Symbol is: EUR
Local is: cs_CZ, Currency Symbol is: CZK
Local is: it_CH, Currency Symbol is: CHF
Local is: ro_RO, Currency Symbol is: RON
Local is: es_PR, Currency Symbol is: $
Local is: en_CA, Currency Symbol is: CAD
Local is: de_DE, Currency Symbol is: EUR
Local is: ga
Local is: de_LU, Currency Symbol is: EUR
Local is: de
Local is: es_AR, Currency Symbol is: ARS
Local is: sk
Local is: ms_MY, Currency Symbol is: MYR
Local is: hr_HR, Currency Symbol is: HRK
Local is: en_SG, Currency Symbol is: SGD
Local is: da
Local is: mt
Local is: pl
Local is: tr
Local is: el
Local is: ms
Local is: sv_SE, Currency Symbol is: SEK
Local is: da_DK, Currency Symbol is: DKK
Local is: es_HN, Currency Symbol is: HNL
Thanks
Related Tutorials/Questions & Answers:
Currency Symbol problemCurrency Symbol problem Hi All,
My Server side code...
Symbol is: PEN
Local is: en
Local is: es_PA,
Currency Symbol is: PAB
Local is: sr_BA,
Currency Symbol is: BAM
Local is: mk
Local is: es_GT,
Currency Symbol Advertisements
currency convertercurrency converter hi i have encountered a
problem while creating a pdf file in jsp....
my
problem is i want commas for the
currency which is diplayed in the pdf file...
i'm using sybase, stored procedure for the front end
currency conversion currency conversion hi frds..
I wan jsp code to convert
currency in different formats??... if u know plz plz plz post it
Please visit the following link:
http://www.roseindia.net/tutorials/I18N/currency
ModuleNotFoundError: No module named 'Currency'ModuleNotFoundError: No module named '
Currency' Hi,
My Python... '
Currency'
How to remove the ModuleNotFoundError: No module named '
Currency... to install padas library.
You can install
Currency python with following
ModuleNotFoundError: No module named 'Currency'ModuleNotFoundError: No module named '
Currency' Hi,
My Python... '
Currency'
How to remove the ModuleNotFoundError: No module named '
Currency... to install padas library.
You can install
Currency python with following
currency - Java Beginnerscurrency helo guys can you share me a code about
Currency... Mexican pesos
sample input:
ENTER TYPE OF
CURRENCY:(so the user must choose a
currency if dollars,swiss francs,euro dollars or mexican pesos)sample I input
javascript regex validate currencyjavascript regex validate currency How to validate
currency in JavaScript?
<html>
<head>
<title>
Currency validation... validate() {
var
currency = document.getElementById("
currency").value
Java Currency Converter Java
Currency Converter Hi I was wondering if someone could help me write a program to convert Pounds into Euro's. The program should prompt the user to input the number of pounds and output the number of Euros
currency - Java Beginnerscurrency helo guys can you share me a "JAVAcode" about
Currency...=9.815 Mexican pesos
sample input:
ENTER TYPE OF
CURRENCY:(so the user must choose a
currency if dollars,swiss francs,euro dollars or mexican pesos)sample I
Java array in currency converterJava array in
currency converter Hi all,
My sister is trying to teach me java. She's in school for programming and I'm not but I am just trying... not have any programming experience. Right now I am working on this
currency Currency Format ExampleCurrency Format Example
This Example shows you how to format
currency according to the locale. In the code given below we are
formatting
Currency according to the locale.
Methods