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. Then print the formatted values as follows:US: formattedPaymentIndia: formattedPaymentChina: formattedPaymentFrance: formattedPaymentwhere is formatted according to the appropriate Locale's currency.Note: India does not have a built-in Locale, so you must construct one where the language is en (i.e., English).Input FormatA single double-precision number denoting .ConstraintsOutput FormatOn the first line, print US: u where is formatted for US currency.On the second line, print India: i where is formatted for Indian currency.On the third line, print China: c where is formatted for Chinese currency.On the fourth line, print France: f, where is formatted for French currency.Sample Input12324.134Sample OutputUS: $12,324.13India: Rs.12,324.13China: ¥12,324.13France: 12 324,13 €
Question
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. Then print the formatted values as follows:US: formattedPaymentIndia: formattedPaymentChina: formattedPaymentFrance: formattedPaymentwhere is formatted according to the appropriate Locale's currency.Note: India does not have a built-in Locale, so you must construct one where the language is en (i.e., English).Input FormatA single double-precision number denoting .ConstraintsOutput FormatOn the first line, print US: u where is formatted for US currency.On the second line, print India: i where is formatted for Indian currency.On the third line, print China: c where is formatted for Chinese currency.On the fourth line, print France: f, where is formatted for French currency.Sample Input12324.134Sample OutputUS: $12,324.13India: Rs.12,324.13China: ¥12,324.13France: 12 324,13 €
Solution
Here is a step-by-step solution in Java:
import java.util.*;
import java.text.*;
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double payment = scanner.nextDouble();
scanner.close();
// Create custom locale for India
Locale indiaLocale = new Locale("en", "IN");
// Create NumberFormats using getCurrencyInstance(), and set Locale
NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat india = NumberFormat.getCurrencyInstance(indiaLocale);
NumberFormat china = NumberFormat.getCurrencyInstance(Locale.CHINA);
NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE);
// Print output to console
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));
}
}
This program does the following:
- Reads a double-precision number from the input.
- Creates a custom Locale for India.
- Creates NumberFormat objects for US, India, China, and France using the getCurrencyInstance() method and the appropriate Locale.
- Formats the input number according to each Locale's currency format.
- Prints the formatted numbers.
Similar Questions
A person is planning a trip abroad and wants to convert their local currency to the destination currency. Write a program for this where the exchange rate is fixed at 1.18. The program should take an amount in one currency as input, convert it to another currency using the exchange rate, and then output the converted amount rounded to two decimal places. Input format :The input consists of double value n, representing the currency.Output format :The output prints the converted currency in double value with two decimal places.
Using the exchange rate and currency amount provided, calculate the counter currency amount, rounded to the appropriate number of decimal places. (Note: Currency symbols are not required) Currency amount: AUD 1665112.91 Exchange rate: 0.7576 Counter currency amount:..... Answer:
Formatting a cell in Currency, you can specifyDecimal placesPercentage symbolCurrency symbolNone of the above
1.Pertanyaan #1Seorang analis melihat bahwa "160" di sel A9 diformat sebagai teks, padahal seharusnya diformat sebagai dolar Australia. Fitur spreadsheet apa yang dapat membantu ia memilih format yang tepat?1 poinFormat sebagai Currency (mata uang)EXCHANGEFormat as DollarCURRENCY
Write a C program, which reads in the amount and prints the number of notes/coins of each denomination. Start with the highest denomination of Indian currency. 23761 x 20001 x 2001 x 1001 x 501 x 201 x 51 x 1
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.