Results 1 to 5 of 5
  1. #1
    md33 is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Default Have too many decimals in my basic program! Please help!

    I'm real new at this. I'm looking for an output that shows a number like this $500.00 instead of $500.00000001. Here's what I have so far-
    import java.text.*;
    import java.util.Scanner;



    public class Commission{

    public static void main (String[] args){
    Scanner kb = new Scanner(System.in);
    double a = 1.1, b, c;

    DecimalFormat formattedDollars= new DecimalFormat("$#,##0.00");








    System.out.println("What is your fixed salary?");
    b = kb.nextDouble();

    c = b * a;

    System.out.println("Your fixed salary is $" + b +" ");
    System.out.println("With the current commission being 10% of total sales," +
    "your total annual compensation is $" + c);


    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Have too many decimals in my basic program! Please help!

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DrummondAW is offline Member
    Join Date
    Oct 2012
    Posts
    13
    Rep Power
    0

    Default Re: Have too many decimals in my basic program! Please help!

    Try this...

    Java Code:
    import java.text.*;
    float thePrice=10.00f;
    System.out.println("The price is " + NumberFormat.getCurrencyInstance().format(thePrice));
    Last edited by DrummondAW; 10-30-2012 at 04:29 AM.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Have too many decimals in my basic program! Please help!

    Quote Originally Posted by DrummondAW View Post
    Try this...

    Java Code:
    import java.text.*;
    float thePrice=10.00f;
    System.out.println("The price is " + NumberFormat.getCurrencyInstance().format(thePrice));
    Please stop spoonfeeding, as that denies the questioner a learning opportunity.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: Have too many decimals in my basic program! Please help!

    Possibly because that code is not in code tags, but I don't see where that DecimalFormat object you've created is actually used.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 2
    Last Post: 07-31-2011, 11:19 PM
  2. Assistance with Basic authentication program
    By Fargo94 in forum New To Java
    Replies: 4
    Last Post: 05-17-2011, 09:22 AM
  3. 3 basic program
    By jasskulainen in forum New To Java
    Replies: 3
    Last Post: 09-27-2009, 01:39 PM
  4. Replies: 1
    Last Post: 07-02-2008, 01:58 PM
  5. Basic Program Please Help!!
    By VinceGuad in forum New To Java
    Replies: 3
    Last Post: 02-01-2008, 03:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •