Read Time:1 Minute, 1 Second
use the NumberFormat class’ getCurrencyInstance method to convert into the US, Indian, Chinese, French and many more currency formats.
public Locale(String language, String country, String variant)
Construct a locale from language, country and variant. This constructor normalizes the language value to lowercase and the country value to uppercase.
Locale IND = new Locale("en", "IN");
NumberFormat india = NumberFormat.getCurrencyInstance(IND);
int money = 1458
System.out.print(india.format(money));
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double payment = scanner.nextDouble();
scanner.close();
String us= NumberFormat.getCurrencyInstance(Locale.US).format(payment);
String china= NumberFormat.getCurrencyInstance(Locale.CHINA).format(payment);
String france= NumberFormat.getCurrencyInstance(Locale.FRANCE).format(payment);
String india= NumberFormat.getCurrencyInstance(new Locale("en","IN")).format(payment);
// Write your code here.
System.out.println("US: " + us);
System.out.println("India: " + india);
System.out.println("China: " + china);
System.out.println("France: " + france);
}
}