Solved

Reduce % size

Posted on 2011-02-18
5
270 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.

808 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