Java Currency Formatter

  • + 1 comment

    The key changes:

    1) Use NumberFormat.getCurrencyInstance() instead of getNumberInstance() - this automatically handles: - Currency symbols - Thousand separators - Decimal formatting

    2) Create proper Locale objects for each country: - Locale.US for United States - new Locale("en", "IN") for India (English language, India country) - Locale.CHINA for China - Locale.FRANCE for France

    3) The getCurrencyInstance() method automatically formats numbers according to each locale's conventions, including: - Correct currency symbols ($ for US, Rs. for India, ¥ for China, € for France) - Proper grouping separators (commas, spaces, etc.) - Decimal separators (periods or commas depending on locale)

    This solution will produce the exact output shown in your sample, with proper formatting for each currency.