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

LVL 1
InquisitiveProgrammerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
for_yanConnect With a Mentor Commented:
check this:

        DecimalFormat fff = new DecimalFormat("$#####.00");
        System.out.println(fff.format(345.6789));

               System.out.println(fff.format(365.0));

        System.out.println(fff.format(365));

Open in new window


Output:
$345.68
$365.00
$365.00

Open in new window

0
 
InquisitiveProgrammerAuthor Commented:
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.
0
 
for_yanCommented:

   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

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
InquisitiveProgrammerAuthor Commented:
I found my bug, thanks.
0
 
for_yanCommented:
That  would be really strange

If you just do

System.out.println("$256.00")

does it print dollar sign ?
0
 
for_yanCommented:
Great!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.