Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reduce % size

Posted on 2011-02-18
5
Medium Priority
?
275 Views
Last Modified: 2012-05-11
Please advise how to make correct percentage view with only 2 digits after comma.
now I have:
System.out.println("    Margin use = " + (u / c * 100) + "%")
.............
output

 Margin use = 1.5060808012349864%

Open in new window

0
Comment
Question by:gbcbr
[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
5 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 34927583
I think you should use DecimalFormat like

http://www.roseindia.net/java/beginners/DecimalFormatExample.shtml
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 34927660
so if you have it like that:

    double amount = (u / c * 100);
    NumberFormat formatter = new DecimalFormat("#0.00");
System.out.println  ("Margin Use = " + formatter.format(amount) + "%")

     
0
 

Author Comment

by:gbcbr
ID: 34927707
Thank you, I make it even easy
        NumberFormat formatter = new DecimalFormat("#0.00");
        System.out.println("    Margin use = " + formatter.format(u / c * 100) + "%");
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34927718
Yes, it is of course also possible
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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

610 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