Hello everyone, nice to meet you again. I am Phyo Pyae. Last - TopicsExpress



          

Hello everyone, nice to meet you again. I am Phyo Pyae. Last week, I shared about the TimeZone with the example program. For this week, I would like to share about the Currency class. Currency is useful when implement the business program or application because you can get the currency code from the program by using Currency.getInstance(Locale locale) method. For example: Currency.getInstance(Locale US) will return USD. Another one is the NumberFormat.getCurrencyInstance(locale) method. It can create an instance of a NumberFormat object that can be used to format and parse currency values for the given locale. It returns a String that includes the formatted number and the appropriate currency sign. Ok lets see the example. ------------------------------------------------------------------- public static void main(String args[])   {     Locale localeJapan = Locale.JAPAN;     Locale localeUK = Locale.UK;     Locale localeUS = Locale.US;     Double currencyAmount = 1234567.89;     Currency currencyJapan = Currency.getInstance(localeJapan);     Currency currencyUK = Currency.getInstance(localeUK);     Currency currencyUS = Currency.getInstance(localeUS);     NumberFormat currFormatJapan = NumberFormat.getCurrencyInstance(localeJapan);     NumberFormat currFormatUK = NumberFormat.getCurrencyInstance(localeUK);     NumberFormat currFormatUS = NumberFormat.getCurrencyInstance(localeUS);     System.out.println(Japans currency :         + currencyJapan.getCurrencyCode() +         + currFormatJapan.format(currencyAmount));     System.out.println(UKs currency : + currencyUK.getCurrencyCode()         + + currFormatUK.format(currencyAmount));     System.out.println(USs currency : + currencyUS.getCurrencyCode()         + + currFormatUS.format(currencyAmount));   } ------------------------------------------------------------------- The above program will display as follows: ------------------------------------------------------------------- Japans currency : JPY ¥1,234,568 UKs currency : GBP £1,234,567.89 USs currency : USD $1,234,567.89 ------------------------------------------------------------------- I hope everyone will enjoy about this topic and use it well. See you next time!
Posted on: Fri, 17 Oct 2014 10:53:04 +0000

Trending Topics



Recently Viewed Topics




© 2015