Showing posts with label Price Format By Country. Show all posts
Showing posts with label Price Format By Country. Show all posts

Friday, June 6, 2014

Java Formatting Price/Number According To Country/Currency

External Link


CurrencyFormat.java


import java.util.*;
import java.lang.*;
import java.text.*;


class CurrencyFormat {
 public static void main (String[] args) throws java.lang.Exception {
 Map<String, String> languagesMap = new TreeMap<String, String>();
        Locale[] locales = Locale.getAvailableLocales();
        for (Locale obj : locales) {
            if ((obj.getDisplayCountry() != null) && (!"".equals(obj.getDisplayCountry()))) {
                languagesMap.put(obj.getCountry(), obj.getLanguage());
            }
        }

        String[] countries = Locale.getISOCountries();
        int supportedLocale = 0, nonSupportedLocale = 0;
        for (String countryCode : countries) {
            Locale obj = null;
            if (languagesMap.get(countryCode) == null) {
                obj = new Locale("", countryCode);
                nonSupportedLocale++;
            }
            else {
                //create a Locale with own country's languages
                obj = new Locale(languagesMap.get(countryCode), countryCode);
                supportedLocale++;

            }
            NumberFormat currency = NumberFormat.getCurrencyInstance(obj);
            DecimalFormatSymbols decimalFormatSymbols = ((DecimalFormat) currency).getDecimalFormatSymbols();
            String currencySymbol = decimalFormatSymbols.getCurrencySymbol();
            decimalFormatSymbols.setCurrencySymbol("");
            ((DecimalFormat) currency).setDecimalFormatSymbols(decimalFormatSymbols);

            System.out.println("Country Code = " + obj.getISO3Country()
                    + ", Price = " + currency.format(35147869.3518).trim()
                    + ", Symbol: " + currencySymbol
                    + ", Name: " + decimalFormatSymbols.getCurrency().getDisplayName()
                    + ", Code: " + decimalFormatSymbols.getCurrency().getCurrencyCode()
                    + ", Country Name = " + obj.getDisplayCountry(obj)
                    + ", Country Name = " + obj.getDisplayCountry()
                    + ", Languages = " + obj.getDisplayLanguage());
        }
        System.out.println("nonSupportedLocale : " + nonSupportedLocale);
        System.out.println("supportedLocale : " + supportedLocale);
    }
}

Output


Country Code = AND, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = ARE, Price = 35,147,869.35, Symbol: د.إ.‏, Code: AED
Country Code = AFG, Price = 35,147,869.35, Symbol: AFN, Code: AFN
Country Code = ATG, Price = 35,147,869.35, Symbol: XCD, Code: XCD
Country Code = AIA, Price = 35,147,869.35, Symbol: XCD, Code: XCD
Country Code = ALB, Price = 35.147.869,35, Symbol: Lek, Code: ALL
Country Code = ARM, Price = 35,147,869.35, Symbol: AMD, Code: AMD
Country Code = ANT, Price = 35,147,869.35, Symbol: ANG, Code: ANG
Country Code = AGO, Price = 35,147,869.35, Symbol: AOA, Code: AOA
Country Code = ATA, Price = 35,147,869.35, Symbol: ¤, Code: XXX
Country Code = ARG, Price = 35.147.869,35, Symbol: $, Code: ARS
Country Code = ASM, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = AUT, Price = 35.147.869,35, Symbol: €, Code: EUR
Country Code = AUS, Price = 35,147,869.35, Symbol: $, Code: AUD
Country Code = ABW, Price = 35,147,869.35, Symbol: AWG, Code: AWG
Country Code = ALA, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = AZE, Price = 35,147,869.35, Symbol: AZN, Code: AZN
Country Code = BIH, Price = 35.147.869,35, Symbol: КМ., Code: BAM
Country Code = BRB, Price = 35,147,869.35, Symbol: BBD, Code: BBD
Country Code = BGD, Price = 35,147,869.35, Symbol: BDT, Code: BDT
Country Code = BEL, Price = 35.147.869,35, Symbol: €, Code: EUR
Country Code = BFA, Price = 35,147,869, Symbol: XOF, Code: XOF
Country Code = BGR, Price = 35 147 869,35, Symbol: лв., Code: BGN
Country Code = BHR, Price = 35,147,869.352, Symbol: د.ب.‏, Code: BHD
Country Code = BDI, Price = 35,147,869, Symbol: BIF, Code: BIF
Country Code = BEN, Price = 35,147,869, Symbol: XOF, Code: XOF
Country Code = BLM, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = BMU, Price = 35,147,869.35, Symbol: BMD, Code: BMD
Country Code = BRN, Price = 35,147,869.35, Symbol: BND, Code: BND
Country Code = BOL, Price = 35.147.869,35, Symbol: B$, Code: BOB
Country Code = BES, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = BRA, Price = 35.147.869,35, Symbol: R$, Code: BRL
Country Code = BHS, Price = 35,147,869.35, Symbol: BSD, Code: BSD
Country Code = BTN, Price = 35,147,869.35, Symbol: BTN, Code: BTN
Country Code = BVT, Price = 35,147,869.35, Symbol: NOK, Code: NOK
Country Code = BWA, Price = 35,147,869.35, Symbol: BWP, Code: BWP
Country Code = BLR, Price = 35 147 869, Symbol: Руб, Code: BYR
Country Code = BLZ, Price = 35,147,869.35, Symbol: BZD, Code: BZD
Country Code = CAN, Price = 35 147 869,35, Symbol: $, Code: CAD
Country Code = CCK, Price = 35,147,869.35, Symbol: AUD, Code: AUD
Country Code = COD, Price = 35,147,869.35, Symbol: CDF, Code: CDF
Country Code = CAF, Price = 35,147,869, Symbol: XAF, Code: XAF
Country Code = COG, Price = 35,147,869, Symbol: XAF, Code: XAF
Country Code = CHE, Price = 35'147'869.35, Symbol: SFr., Code: CHF
Country Code = CIV, Price = 35,147,869, Symbol: XOF, Code: XOF
Country Code = COK, Price = 35,147,869.35, Symbol: NZD, Code: NZD
Country Code = CHL, Price = 35.147.869, Symbol: Ch$, Code: CLP
Country Code = CMR, Price = 35,147,869, Symbol: XAF, Code: XAF
Country Code = CHN, Price = 35,147,869.35, Symbol: ¥, Code: CNY
Country Code = COL, Price = 35.147.869,35, Symbol: $, Code: COP
Country Code = CRI, Price = 35,147,869.35, Symbol: C, Code: CRC
Country Code = CUB, Price = 35,147,869.35, Symbol: CUP, Code: CUP
Country Code = CPV, Price = 35,147,869.35, Symbol: CVE, Code: CVE
Country Code = CUW, Price = 35,147,869.35, Symbol: ANG, Code: ANG
Country Code = CXR, Price = 35,147,869.35, Symbol: AUD, Code: AUD
Country Code = CYP, Price = 35.147.869,35, Symbol: €, Code: EUR
Country Code = CZE, Price = 35 147 869,35, Symbol: Kč, Code: CZK
Country Code = DEU, Price = 35.147.869,35, Symbol: €, Code: EUR
Country Code = DJI, Price = 35,147,869, Symbol: DJF, Code: DJF
Country Code = DNK, Price = 35.147.869,35, Symbol: kr, Code: DKK
Country Code = DMA, Price = 35,147,869.35, Symbol: XCD, Code: XCD
Country Code = DOM, Price = 35,147,869.35, Symbol: RD$, Code: DOP
Country Code = DZA, Price = 35,147,869.35, Symbol: د.ج.‏, Code: DZD
Country Code = ECU, Price = 35.147.869,35, Symbol: $, Code: USD
Country Code = EST, Price = 35 147 869,35, Symbol: €, Code: EUR
Country Code = EGY, Price = 35,147,869.35, Symbol: ج.م.‏, Code: EGP
Country Code = ESH, Price = 35,147,869.35, Symbol: MAD, Code: MAD
Country Code = ERI, Price = 35,147,869.35, Symbol: ERN, Code: ERN
Country Code = ESP, Price = 35.147.869,35, Symbol: €, Code: EUR
Country Code = ETH, Price = 35,147,869.35, Symbol: ETB, Code: ETB
Country Code = FIN, Price = 35 147 869,35, Symbol: €, Code: EUR
Country Code = FJI, Price = 35,147,869.35, Symbol: FJD, Code: FJD
Country Code = FLK, Price = 35,147,869.35, Symbol: FKP, Code: FKP
Country Code = FSM, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = FRO, Price = 35,147,869.35, Symbol: DKK, Code: DKK
Country Code = FRA, Price = 35 147 869,35, Symbol: €, Code: EUR
Country Code = GAB, Price = 35,147,869, Symbol: XAF, Code: XAF
Country Code = GBR, Price = 35,147,869.35, Symbol: £, Code: GBP
Country Code = GRD, Price = 35,147,869.35, Symbol: XCD, Code: XCD
Country Code = GEO, Price = 35,147,869.35, Symbol: GEL, Code: GEL
Country Code = GUF, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = GGY, Price = 35,147,869.35, Symbol: GBP, Code: GBP
Country Code = GHA, Price = 35,147,869.35, Symbol: GHS, Code: GHS
Country Code = GIB, Price = 35,147,869.35, Symbol: GIP, Code: GIP
Country Code = GRL, Price = 35,147,869.35, Symbol: DKK, Code: DKK
Country Code = GMB, Price = 35,147,869.35, Symbol: GMD, Code: GMD
Country Code = GIN, Price = 35,147,869, Symbol: GNF, Code: GNF
Country Code = GLP, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = GNQ, Price = 35,147,869, Symbol: XAF, Code: XAF
Country Code = GRC, Price = 35.147.869,35, Symbol: €, Code: EUR
Country Code = SGS, Price = 35,147,869.35, Symbol: GBP, Code: GBP
Country Code = GTM, Price = 35,147,869.35, Symbol: Q, Code: GTQ
Country Code = GUM, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = GNB, Price = 35,147,869, Symbol: XOF, Code: XOF
Country Code = GUY, Price = 35,147,869.35, Symbol: GYD, Code: GYD
Country Code = HKG, Price = 35,147,869.35, Symbol: HK$, Code: HKD
Country Code = HMD, Price = 35,147,869.35, Symbol: AUD, Code: AUD
Country Code = HND, Price = 35,147,869.35, Symbol: L, Code: HNL
Country Code = HRV, Price = 35.147.869,35, Symbol: Kn, Code: HRK
Country Code = HTI, Price = 35,147,869.35, Symbol: HTG, Code: HTG
Country Code = HUN, Price = 35 147 869,35, Symbol: Ft, Code: HUF
Country Code = IDN, Price = 35.147.869,35, Symbol: Rp, Code: IDR
Country Code = IRL, Price = 35,147,869.35, Symbol: €, Code: EUR
Country Code = ISR, Price = 35,147,869.35, Symbol: ש"ח, Code: ILS
Country Code = IMN, Price = 35,147,869.35, Symbol: GBP, Code: GBP
Country Code = IND, Price = 35,147,869.35, Symbol: Rs., Code: INR
Country Code = IOT, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = IRQ, Price = 35,147,869.352, Symbol: د.ع.‏, Code: IQD
Country Code = IRN, Price = 35,147,869.35, Symbol: IRR, Code: IRR
Country Code = ISL, Price = 35.147.869,, Symbol: kr., Code: ISK
Country Code = ITA, Price = 35.147.869,35, Symbol: €, Code: EUR
Country Code = JEY, Price = 35,147,869.35, Symbol: GBP, Code: GBP
Country Code = JAM, Price = 35,147,869.35, Symbol: JMD, Code: JMD
Country Code = JOR, Price = 35,147,869.352, Symbol: د.أ.‏, Code: JOD
Country Code = JPN, Price = 35,147,869, Symbol: ¥, Code: JPY
Country Code = KEN, Price = 35,147,869.35, Symbol: KES, Code: KES
Country Code = KGZ, Price = 35,147,869.35, Symbol: KGS, Code: KGS
Country Code = KHM, Price = 35,147,869.35, Symbol: KHR, Code: KHR
Country Code = KIR, Price = 35,147,869.35, Symbol: AUD, Code: AUD
Country Code = COM, Price = 35,147,869, Symbol: KMF, Code: KMF
Country Code = KNA, Price = 35,147,869.35, Symbol: XCD, Code: XCD
Country Code = PRK, Price = 35,147,869.35, Symbol: KPW, Code: KPW
Country Code = KOR, Price = 35,147,869, Symbol: ₩, Code: KRW
Country Code = KWT, Price = 35,147,869.352, Symbol: د.ك.‏, Code: KWD
Country Code = CYM, Price = 35,147,869.35, Symbol: KYD, Code: KYD
Country Code = KAZ, Price = 35,147,869.35, Symbol: KZT, Code: KZT
Country Code = LAO, Price = 35,147,869.35, Symbol: LAK, Code: LAK
Country Code = LBN, Price = 35,147,869.35, Symbol: ل.ل.‏, Code: LBP
Country Code = LCA, Price = 35,147,869.35, Symbol: XCD, Code: XCD
Country Code = LIE, Price = 35,147,869.35, Symbol: CHF, Code: CHF
Country Code = LKA, Price = 35,147,869.35, Symbol: LKR, Code: LKR
Country Code = LBR, Price = 35,147,869.35, Symbol: LRD, Code: LRD
Country Code = LSO, Price = 35,147,869.35, Symbol: LSL, Code: LSL
Country Code = LTU, Price = 35 147 869,35, Symbol: Lt, Code: LTL
Country Code = LUX, Price = 35.147.869,35, Symbol: €, Code: EUR
Country Code = LVA, Price = 35 147 869,35, Symbol: Ls, Code: LVL
Country Code = LBY, Price = 35,147,869.352, Symbol: د.ل.‏, Code: LYD
Country Code = MAR, Price = 35,147,869.35, Symbol: د.م.‏, Code: MAD
Country Code = MCO, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = MDA, Price = 35,147,869.35, Symbol: MDL, Code: MDL
Country Code = MNE, Price = 35.147.869,35, Symbol: €, Code: EUR
Country Code = MAF, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = MDG, Price = 35,147,869.35, Symbol: MGA, Code: MGA
Country Code = MHL, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = MKD, Price = 35.147.869,35, Symbol: Den, Code: MKD
Country Code = MLI, Price = 35,147,869, Symbol: XOF, Code: XOF
Country Code = MMR, Price = 35,147,869.35, Symbol: MMK, Code: MMK
Country Code = MNG, Price = 35,147,869.35, Symbol: MNT, Code: MNT
Country Code = MAC, Price = 35,147,869.35, Symbol: MOP, Code: MOP
Country Code = MNP, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = MTQ, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = MRT, Price = 35,147,869.35, Symbol: MRO, Code: MRO
Country Code = MSR, Price = 35,147,869.35, Symbol: XCD, Code: XCD
Country Code = MLT, Price = 35,147,869.35, Symbol: €, Code: EUR
Country Code = MUS, Price = 35,147,869.35, Symbol: MUR, Code: MUR
Country Code = MDV, Price = 35,147,869.35, Symbol: MVR, Code: MVR
Country Code = MWI, Price = 35,147,869.35, Symbol: MWK, Code: MWK
Country Code = MEX, Price = 35,147,869.35, Symbol: $, Code: MXN
Country Code = MYS, Price = 35,147,869.35, Symbol: RM, Code: MYR
Country Code = MOZ, Price = 35,147,869.35, Symbol: MZN, Code: MZN
Country Code = NAM, Price = 35,147,869.35, Symbol: NAD, Code: NAD
Country Code = NCL, Price = 35,147,869, Symbol: XPF, Code: XPF
Country Code = NER, Price = 35,147,869, Symbol: XOF, Code: XOF
Country Code = NFK, Price = 35,147,869.35, Symbol: AUD, Code: AUD
Country Code = NGA, Price = 35,147,869.35, Symbol: NGN, Code: NGN
Country Code = NIC, Price = 35,147,869.35, Symbol: $C, Code: NIO
Country Code = NLD, Price = 35.147.869,35, Symbol: €, Code: EUR
Country Code = NOR, Price = 35 147 869,35, Symbol: kr, Code: NOK
Country Code = NPL, Price = 35,147,869.35, Symbol: NPR, Code: NPR
Country Code = NRU, Price = 35,147,869.35, Symbol: AUD, Code: AUD
Country Code = NIU, Price = 35,147,869.35, Symbol: NZD, Code: NZD
Country Code = NZL, Price = 35,147,869.35, Symbol: $, Code: NZD
Country Code = OMN, Price = 35,147,869.352, Symbol: ر.ع.‏, Code: OMR
Country Code = PAN, Price = 35,147,869.35, Symbol: B, Code: PAB
Country Code = PER, Price = 35.147.869,35, Symbol: S/, Code: PEN
Country Code = PYF, Price = 35,147,869, Symbol: XPF, Code: XPF
Country Code = PNG, Price = 35,147,869.35, Symbol: PGK, Code: PGK
Country Code = PHL, Price = 35,147,869.35, Symbol: Php, Code: PHP
Country Code = PAK, Price = 35,147,869.35, Symbol: PKR, Code: PKR
Country Code = POL, Price = 35 147 869,35, Symbol: zł, Code: PLN
Country Code = SPM, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = PCN, Price = 35,147,869.35, Symbol: NZD, Code: NZD
Country Code = PRI, Price = 35,147,869.35, Symbol: $, Code: USD
Country Code = PSE, Price = 35,147,869.35, Symbol: ILS, Code: ILS
Country Code = PRT, Price = 35.147.869,35, Symbol: €, Code: EUR
Country Code = PLW, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = PRY, Price = 35.147.869, Symbol: G, Code: PYG
Country Code = QAT, Price = 35,147,869.35, Symbol: ر.ق.‏, Code: QAR
Country Code = REU, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = ROU, Price = 35.147.869,35, Symbol: LEI, Code: RON
Country Code = SRB, Price = 35.147.869,35, Symbol: дин., Code: RSD
Country Code = RUS, Price = 35 147 869,35, Symbol: руб., Code: RUB
Country Code = RWA, Price = 35,147,869, Symbol: RWF, Code: RWF
Country Code = SAU, Price = 35,147,869.35, Symbol: ر.س.‏, Code: SAR
Country Code = SLB, Price = 35,147,869.35, Symbol: SBD, Code: SBD
Country Code = SYC, Price = 35,147,869.35, Symbol: SCR, Code: SCR
Country Code = SDN, Price = 35,147,869.35, Symbol: ج.س.‏, Code: SDG
Country Code = SWE, Price = 35 147 869,35, Symbol: kr, Code: SEK
Country Code = SGP, Price = 35,147,869.35, Symbol: S$, Code: SGD
Country Code = SHN, Price = 35,147,869.35, Symbol: SHP, Code: SHP
Country Code = SVN, Price = 35.147.869,35, Symbol: €, Code: EUR
Country Code = SJM, Price = 35,147,869.35, Symbol: NOK, Code: NOK
Country Code = SVK, Price = 35 147 869,35, Symbol: €, Code: EUR
Country Code = SLE, Price = 35,147,869.35, Symbol: SLL, Code: SLL
Country Code = SMR, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = SEN, Price = 35,147,869, Symbol: XOF, Code: XOF
Country Code = SOM, Price = 35,147,869.35, Symbol: SOS, Code: SOS
Country Code = SUR, Price = 35,147,869.35, Symbol: SRD, Code: SRD
Country Code = STP, Price = 35,147,869.35, Symbol: STD, Code: STD
Country Code = SLV, Price = 35,147,869.35, Symbol: C, Code: SVC
Country Code = SXM, Price = 35,147,869.35, Symbol: ANG, Code: ANG
Country Code = SYR, Price = 35,147,869.35, Symbol: ل.س.‏, Code: SYP
Country Code = SWZ, Price = 35,147,869.35, Symbol: SZL, Code: SZL
Country Code = TCA, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = TCD, Price = 35,147,869, Symbol: XAF, Code: XAF
Country Code = ATF, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = TGO, Price = 35,147,869, Symbol: XOF, Code: XOF
Country Code = THA, Price = 35,147,869.35, Symbol: ฿, Code: THB
Country Code = TJK, Price = 35,147,869.35, Symbol: TJS, Code: TJS
Country Code = TKL, Price = 35,147,869.35, Symbol: NZD, Code: NZD
Country Code = TLS, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = TKM, Price = 35,147,869.35, Symbol: TMT, Code: TMT
Country Code = TUN, Price = 35,147,869.352, Symbol: د.ت.‏, Code: TND
Country Code = TON, Price = 35,147,869.35, Symbol: TOP, Code: TOP
Country Code = TUR, Price = 35.147.869,35, Symbol: TL, Code: TRY
Country Code = TTO, Price = 35,147,869.35, Symbol: TTD, Code: TTD
Country Code = TUV, Price = 35,147,869.35, Symbol: AUD, Code: AUD
Country Code = TWN, Price = 35,147,869.35, Symbol: NT$, Code: TWD
Country Code = TZA, Price = 35,147,869.35, Symbol: TZS, Code: TZS
Country Code = UKR, Price = 35 147 869,35, Symbol: грн., Code: UAH
Country Code = UGA, Price = 35,147,869.35, Symbol: UGX, Code: UGX
Country Code = UMI, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = USA, Price = 35,147,869.35, Symbol: $, Code: USD
Country Code = URY, Price = 35.147.869,35, Symbol: NU$, Code: UYU
Country Code = UZB, Price = 35,147,869.35, Symbol: UZS, Code: UZS
Country Code = VAT, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = VCT, Price = 35,147,869.35, Symbol: XCD, Code: XCD
Country Code = VEN, Price = 35.147.869,35, Symbol: Bs.F., Code: VEF
Country Code = VGB, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = VIR, Price = 35,147,869.35, Symbol: USD, Code: USD
Country Code = VNM, Price = 35.147.869,35, Symbol: đ, Code: VND
Country Code = VUT, Price = 35,147,869, Symbol: VUV, Code: VUV
Country Code = WLF, Price = 35,147,869, Symbol: XPF, Code: XPF
Country Code = WSM, Price = 35,147,869.35, Symbol: WST, Code: WST
Country Code = YEM, Price = 35,147,869.35, Symbol: ر.ي.‏, Code: YER
Country Code = MYT, Price = 35,147,869.35, Symbol: EUR, Code: EUR
Country Code = ZAF, Price = 35,147,869.35, Symbol: R, Code: ZAR
Country Code = ZMB, Price = 35,147,869.35, Symbol: ZMK, Code: ZMK
Country Code = ZWE, Price = 35,147,869.35, Symbol: ZWL, Code: ZWL
nonSupportedLocale : 155
supportedLocale : 94