Java Beginner Programming Question

Hi, I need help with the following:
public String toString()
		return (description + price * units);

Open in new window

This command will get me the following result with this input (Ex: Description=Jeans, Price=$59.95, Units =12 will get me the following return)

Open in new window

How would I go about modifying my return command to represent the following:

Jacket $719.00 

Open in new window

Simply adding the string for $ sign and restricting the output to only 2 decimals.

Who is Participating?
n2fcConnect With a Mentor Commented:
import java.text.DecimalFormat;
DecimalFormat df = new DecimalFormat( "#########0.00");
return (description + " $" + df.format(price * units));

Open in new window

CPColinSenior Java ArchitectCommented:
java.text.NumberFormat.getCurrencyInstance() will return a NumberFormat object that should get you what you want.
nitro55Author Commented:
Thanks bud.
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.