Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Java Beginner Programming Question

Posted on 2013-01-30
3
Medium Priority
?
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 20

Accepted Solution

by:
n2fc earned 2000 total points
ID: 38837852
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
ID: 38837856
java.text.NumberFormat.getCurrencyInstance() will return a NumberFormat object that should get you what you want.
0
 

Author Closing Comment

by:nitro55
ID: 38837880
Thanks bud.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 …
This video teaches viewers about errors in exception handling.
Suggested Courses

722 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