Solved

Java Beginner Programming Question

Posted on 2013-01-30
3
254 Views
Last Modified: 2013-01-30
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)
Jacket719.000000001

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.

Help?
0
Comment
Question by:nitro55
3 Comments
 
LVL 19

Accepted Solution

by:
n2fc earned 500 total points
Comment Utility
import java.text.DecimalFormat;
...
DecimalFormat df = new DecimalFormat( "#########0.00");
...
return (description + " $" + df.format(price * units));

Open in new window

0
 
LVL 14

Expert Comment

by:CPColin
Comment Utility
java.text.NumberFormat.getCurrencyInstance() will return a NumberFormat object that should get you what you want.
0
 

Author Closing Comment

by:nitro55
Comment Utility
Thanks bud.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Receive file in Servlet 1 36
pairstar challenge 2 41
maven example error 3 34
get weblogic logged in user in java 2 39
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now