Solved

Reduce % size

Posted on 2011-02-18
5
271 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
  • 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 125 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
 
LVL 92

Expert Comment

by:objects
ID: 34929625
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
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.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

829 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