Format Doubles to Dollars in Java – Java #59

*Watch copying and pasting the quotation marks, you may have to retype them to avoid an error
————–Code Screenshots————

———————Beginning of Source Code————————-
/****************************************************
Programmer: Akinwale Owi
Company:Dagba Computers
Program Description:Format Doubles to Dollars
***********************************************************/

package straightcash;

//imports
import java.text.NumberFormat;
import java.util.Scanner; //scanner to read in values
import java.util.Locale; //for location

public class StraightCash
{

public static void main(String[] args)
{
//Creating a Scanner
Scanner dirtyMoney = new Scanner(System.in);

//asking user for number
System.out.println(“Please enter a number to change to dollars”);

//variable to hold dollars
double preFormat = dirtyMoney.nextDouble();

//printing out preDollars to check
System.out.println(“Before formatting = ” + preFormat);

//creating locale for U.S. dollars
Locale US = new Locale(“en”, “US”);

//Creating Number Format Object for US
NumberFormat form = NumberFormat.getCurrencyInstance(US);

//Printing out formatted dollars to check
System.out.println(“Formatted for US Dollars = ” + (form.format(preFormat)));

}//end of main

}//End of program/end of StraightCash class (contains main)
———————End of Source Code——————————-

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: