Solved

Java Beginner Programming Question

Posted on 2013-01-30
3
262 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 500 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

617 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