java currency formatter code example
Example 1: java how to create india currency
NumberFormat format = NumberFormat.getCurrencyInstance(new Locale("en", "in")).format(d);
Example 2: Given a double-precision number, , denoting an amount of money, use the NumberFormat class' getCurrencyInstance method to convert into the US, Indian, Chinese, and French currency formats
import java.util.Scanner;
import java.text.NumberFormat;
import java.util.Locale;
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double payment = scanner.nextDouble();
scanner.close();
Locale indiaLocale = new Locale("en", "IN");
NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat india = NumberFormat.getCurrencyInstance(indiaLocale);
NumberFormat china = NumberFormat.getCurrencyInstance(Locale.CHINA);
NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE);
System.out.println("US: " + us.format(payment));
System.out.println("India: " + india.format(payment));
System.out.println("China: " + china.format(payment));
System.out.println("France: " + france.format(payment));
}
}
Example 3: java format money
double money = 100.1;
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String moneyString = formatter.format(money);
System.out.println(moneyString);