Link to home
Start Free TrialLog in
Avatar of InquisitiveProgrammer
InquisitiveProgrammer

asked on

Help with DecimalFormat

I am trying to append a "$" in front of my number, but for some reason it isn't being added.

Here is a code snippet:

 
// Round the number to two decimal places, then format it properly.
    public String roundTwoDecimals(double number) {
    	DecimalFormat twoDecForm = new DecimalFormat("$0.00");
    	String dollarAmount = twoDecForm.format(number);
    	return dollarAmount;
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of InquisitiveProgrammer
InquisitiveProgrammer

ASKER

It still isn't adding the $ sign.

I'm wondering if it might be something in my Eclipse environment that isn't allowing it to show.

   public static String roundTwoDecimals(double number) {
    	DecimalFormat twoDecForm = new DecimalFormat("$0.00");
    	String dollarAmount = twoDecForm.format(number);
    	return dollarAmount;
    }

    public static void main(String[] args) {

                  System.out.println("  output: " + roundTwoDecimals(365));

}
}

Open in new window



  output: $365.00

Open in new window

I found my bug, thanks.
That  would be really strange

If you just do

System.out.println("$256.00")

does it print dollar sign ?
Great!