Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to add commas to bigger numbers?

  1. #1
    Member
    Join Date
    Jan 2014
    Location
    New Jersey
    Posts
    48
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default How to add commas to bigger numbers?

    Okay so I would like to get commas in my output for bigger numbers like 1,000.00 10,000.00 etc...This is my program. Everything compiles just fine and I get the right output but again would like commas.
    import java.text.DecimalFormat;
    import java.util.Scanner;
    import java.io.*;
     
    public class propertyTax
    {
    	public static void main(String[] args) throws IOException
    	{
    		String fileName;
    		double assessedValue;
    		double taxableAmount;
    		double taxRate;
    		double propTax;
    		String newDecimal1;
    		String newDecimal2;
    		String newDecimal3;
     
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.println("What is the Assessed Value of your property? ");
    		assessedValue = keyboard.nextDouble();
     
    		taxableAmount = (0.92 * assessedValue);
    		taxRate = (0.0105 * taxableAmount);
    		propTax = taxRate;
     
    		DecimalFormat formatter = new DecimalFormat("#0.00");
    		newDecimal1 = (formatter.format(assessedValue));
    		newDecimal2 = (formatter.format(taxableAmount));
    		newDecimal3 = (formatter.format(propTax));
     
    		PrintWriter outputFile = new PrintWriter(new FileWriter("Tax.txt"));
     
    		outputFile.println("Assessed Value:			$" + newDecimal1 + "\n"
    				        +"Taxable Amount:			$" + newDecimal2 + "\n"
    				        +"Tax Rate for each $100.00 	$1.05\n"
    				        +"Property Tax: 	   		$" + newDecimal3 + ".");
     
    		outputFile.close();
    	}
     
    }


    --- Update ---

    These are some of the values that are in/outputted

    Assessed Value: 100000.00
    Taxable Amount: 92000.00


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to add commas to bigger numbers?

    Did you try reading the DecimalFormat API page?

  3. #3
    Member
    Join Date
    Jan 2014
    Location
    New Jersey
    Posts
    48
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: How to add commas to bigger numbers?

    Quote Originally Posted by GregBrannon View Post
    Did you try reading the DecimalFormat API page?
    I will try reading that!

Similar Threads

  1. Need a different way to add Cubed numbers 1-10
    By Dtank123456 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 12th, 2014, 03:02 PM
  2. Java program to add two numbers
    By Prasanth.likith in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 31st, 2014, 03:33 AM
  3. how to add strings as numbers?
    By Dixxon in forum Java Theory & Questions
    Replies: 7
    Last Post: December 8th, 2013, 04:55 PM
  4. How to add the numbers in the following series?
    By namenamename in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 16th, 2013, 07:23 PM
  5. Print array with commas
    By GoPro in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 27th, 2012, 12:41 AM