binary code, binary, binary system-475664.jpg
0 0
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.

https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html#Locale-java.lang.String-java.lang.String-

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.

String india= NumberFormat.getCurrencyInstance(new Locale(“en”,”IN”)).format(payment);

Locale IND = new Locale("en", "IN");
NumberFormat india  = NumberFormat.getCurrencyInstance(IND);
int money = 1458
System.out.print(india.format(money));

Output – Rs. 1,458

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);
    }
}
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

About Author

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *