programming-examples/java/Core_Java/Currency Formatter.java
2019-11-15 12:59:38 +01:00

36 lines
1000 B
Java

Currency Formatter
import java.text.*;
import java.io.*;
class CurrencyFormatter{
public static void main(String[] args)
throws java.io.IOException, java.text.ParseException
{
BufferedReader inStream=
new BufferedReader(new InputStreamReader(System.in));
double currency;
NumberFormat currencyFormatter=
NumberFormat.getCurrencyInstance();
NumberFormat numberFormatter=
NumberFormat.getInstance();
String currencyOut;
System.out.println("Please enter a number to be formatted as currency:\n");
currency=numberFormatter.parse(inStream.readLine()).doubleValue();
currencyOut=currencyFormatter.format(currency);
System.out.println("\n\nThe number formatted as currency is:\n");
System.out.println(currencyOut);
}//close main
}//close class