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:
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;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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));
}
}
output: $365.00
ASKER
I found my bug, thanks.
That would be really strange
If you just do
System.out.println("$256.0 0")
does it print dollar sign ?
If you just do
System.out.println("$256.0
does it print dollar sign ?
Great!
ASKER
I'm wondering if it might be something in my Eclipse environment that isn't allowing it to show.